From cc16603f6f3b6ecce284e926b4a089a4b9fe9d7f Mon Sep 17 00:00:00 2001 From: Jeff Avallone Date: Sun, 23 Nov 2014 17:00:01 -0500 Subject: [PATCH] Adding browserify and es6ify support --- gulpfile.js | 28 ++++++++++++++++++++++++---- package.json | 5 ++++- src/js/main.js | 5 +++++ src/js/test.js | 3 +++ template.html | 2 ++ 5 files changed, 38 insertions(+), 5 deletions(-) create mode 100644 src/js/main.js create mode 100644 src/js/test.js diff --git a/gulpfile.js b/gulpfile.js index 20edb32..14ab63e 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -2,15 +2,19 @@ var gulp = require('gulp'), wrap = require('gulp-wrap'), connect = require('gulp-connect'), 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.watch('./src/**/*.!(html|scss)', ['static']); + gulp.watch('./src/**/*.!(html|scss|js)', ['static']); gulp.watch(['./src/**/*.html', './template.html'], ['markup']); 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' }) .pipe(connect.reload()); return connect.server({ @@ -20,7 +24,7 @@ gulp.task('server', ['static', 'markup', 'compass'], function() { }); gulp.task('static', function() { - return gulp.src('./src/**/*.!(html|scss)') + return gulp.src('./src/**/*.!(html|scss|js)') .pipe(gulp.dest('./build')); }); @@ -40,3 +44,19 @@ gulp.task('compass', function() { 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')); +}); diff --git a/package.json b/package.json index 4833258..1552b23 100644 --- a/package.json +++ b/package.json @@ -10,10 +10,13 @@ "license": "MIT", "private": true, "devDependencies": { + "browserify": "^6.3.2", + "es6ify": "^1.5.1", "gulp": "^3.8.10", "gulp-compass": "^2.0.3", "gulp-connect": "^2.2.0", "gulp-watch": "^2.0.0", - "gulp-wrap": "^0.5.0" + "gulp-wrap": "^0.5.0", + "vinyl-source-stream": "^1.0.0" } } diff --git a/src/js/main.js b/src/js/main.js new file mode 100644 index 0000000..cae76d1 --- /dev/null +++ b/src/js/main.js @@ -0,0 +1,5 @@ +import test from './test'; + +test('foo'); + +console.log('testing'); diff --git a/src/js/test.js b/src/js/test.js new file mode 100644 index 0000000..1a96ce9 --- /dev/null +++ b/src/js/test.js @@ -0,0 +1,3 @@ +export default m => { + console.log(m); +}; diff --git a/template.html b/template.html index 1aa71eb..b175b29 100644 --- a/template.html +++ b/template.html @@ -7,5 +7,7 @@ ${ contents } + +