Adding browserify and es6ify support

This commit is contained in:
Jeff Avallone 2014-11-23 17:00:01 -05:00
parent 9151a47a8e
commit cc16603f6f
5 changed files with 38 additions and 5 deletions

View File

@ -2,15 +2,19 @@ var gulp = require('gulp'),
wrap = require('gulp-wrap'), wrap = require('gulp-wrap'),
connect = require('gulp-connect'), connect = require('gulp-connect'),
watch = require('gulp-watch'), watch = require('gulp-watch'),
compass = require('gulp-compass'); compass = require('gulp-compass'),
browserify = require('browserify'),
es6ify = require('es6ify'),
source = require('vinyl-source-stream');
gulp.task('default', ['server'], function() { gulp.task('default', ['server'], function() {
gulp.watch('./src/**/*.!(html|scss)', ['static']); gulp.watch('./src/**/*.!(html|scss|js)', ['static']);
gulp.watch(['./src/**/*.html', './template.html'], ['markup']); gulp.watch(['./src/**/*.html', './template.html'], ['markup']);
gulp.watch('./src/**/*.scss', ['compass']); gulp.watch('./src/**/*.scss', ['compass']);
gulp.watch('./src/**/*.js', ['browserify']);
}); });
gulp.task('server', ['static', 'markup', 'compass'], function() { gulp.task('server', ['static', 'markup', 'compass', 'browserify'], function() {
watch('./build/**/*', { name: 'Server' }) watch('./build/**/*', { name: 'Server' })
.pipe(connect.reload()); .pipe(connect.reload());
return connect.server({ return connect.server({
@ -20,7 +24,7 @@ gulp.task('server', ['static', 'markup', 'compass'], function() {
}); });
gulp.task('static', function() { gulp.task('static', function() {
return gulp.src('./src/**/*.!(html|scss)') return gulp.src('./src/**/*.!(html|scss|js)')
.pipe(gulp.dest('./build')); .pipe(gulp.dest('./build'));
}); });
@ -40,3 +44,19 @@ gulp.task('compass', function() {
sourcemap: true sourcemap: true
})); }));
}); });
gulp.task('browserify', function() {
var bundler = browserify({
entries: ['./main.js'],
basedir: './src/js',
debug: true,
});
bundler.add(es6ify.runtime);
bundler.transform(es6ify);
return bundler
.bundle()
.pipe(source('js/main.js'))
.pipe(gulp.dest('./build'));
});

View File

@ -10,10 +10,13 @@
"license": "MIT", "license": "MIT",
"private": true, "private": true,
"devDependencies": { "devDependencies": {
"browserify": "^6.3.2",
"es6ify": "^1.5.1",
"gulp": "^3.8.10", "gulp": "^3.8.10",
"gulp-compass": "^2.0.3", "gulp-compass": "^2.0.3",
"gulp-connect": "^2.2.0", "gulp-connect": "^2.2.0",
"gulp-watch": "^2.0.0", "gulp-watch": "^2.0.0",
"gulp-wrap": "^0.5.0" "gulp-wrap": "^0.5.0",
"vinyl-source-stream": "^1.0.0"
} }
} }

5
src/js/main.js Normal file
View File

@ -0,0 +1,5 @@
import test from './test';
test('foo');
console.log('testing');

3
src/js/test.js Normal file
View File

@ -0,0 +1,3 @@
export default m => {
console.log(m);
};

View File

@ -7,5 +7,7 @@
</head> </head>
<body> <body>
${ contents } ${ contents }
<script src="/js/main.js"></script>
</body> </body>
</html> </html>