-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add multiple-file support to recipe gulp.browserify #14
base: master
Are you sure you want to change the base?
Changes from 2 commits
2c4c04d
ccd5e89
a7aea67
0f2b00f
2280dc5
39fb969
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
let app = 'awesome'; | ||
let app = 'awesome'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
*.js | ||
*.js | ||
*.js.map |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
const worker = 'brilliant'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,47 +6,69 @@ var watchify = require('watchify'); | |
var exorcist = require('exorcist'); | ||
var browserify = require('browserify'); | ||
var browserSync = require('browser-sync').create(); | ||
var glob = require('glob'); | ||
var path = require('path'); | ||
var mkdirp = require('mkdirp'); | ||
var eventStream = require('event-stream'); | ||
|
||
// Input file. | ||
watchify.args.debug = true; | ||
var bundler = watchify(browserify('./app/js/app.js', watchify.args)); | ||
/** | ||
* Creating multiple bundles with Watchify | ||
*/ | ||
gulp.task('bundle', function (done) { | ||
glob('./app/js/{app.js,worker/worker.js}', {}, function (err, files) { | ||
if (err) { | ||
done(err); | ||
} | ||
|
||
// Babel transform | ||
bundler.transform(babelify.configure({ | ||
sourceMapRelative: 'app/js' | ||
})); | ||
var tasks = files.map(function (entry) { | ||
var relative = path.relative('./app/js', entry); | ||
|
||
// On updates recompile | ||
bundler.on('update', bundle); | ||
// A workaround for exorcist issue, | ||
// where exorcist fails silently when the output dir does not exist | ||
// see https://github.com/thlorenz/exorcist/issues/18 | ||
// and https://github.com/thlorenz/exorcist/pull/19 | ||
var sourceMapPath = './app/js/dist/' + relative + '.map'; | ||
mkdirp.sync(path.dirname(sourceMapPath)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use asynchronous |
||
|
||
function bundle() { | ||
// Input file. | ||
watchify.args.debug = true; | ||
var bundler = watchify(browserify(entry, watchify.args)); | ||
|
||
gutil.log('Compiling JS...'); | ||
// Babel transform | ||
bundler.transform(babelify.configure({ | ||
sourceMapRelative: 'app/js' | ||
})); | ||
|
||
return bundler.bundle() | ||
.on('error', function (err) { | ||
gutil.log(err.message); | ||
browserSync.notify("Browserify Error!"); | ||
this.emit("end"); | ||
}) | ||
.pipe(exorcist('app/js/dist/bundle.js.map')) | ||
.pipe(source('bundle.js')) | ||
.pipe(gulp.dest('./app/js/dist')) | ||
.pipe(browserSync.stream({once: true})); | ||
} | ||
var bundle = function () { | ||
gutil.log('Compiling ' + entry + '...'); | ||
|
||
/** | ||
* Gulp task alias | ||
*/ | ||
gulp.task('bundle', function () { | ||
return bundle(); | ||
return bundler.bundle() | ||
.on('error', function (err) { | ||
gutil.log(err.message); | ||
browserSync.notify('Browserify Error!'); | ||
this.emit('end'); | ||
}) | ||
.pipe(exorcist(sourceMapPath)) | ||
.pipe(source(relative)) | ||
.pipe(gulp.dest('./app/js/dist')) | ||
.pipe(browserSync.stream({once: true})); | ||
} | ||
|
||
// On updates recompile | ||
bundler.on('update', bundle); | ||
|
||
return bundle(); | ||
}); | ||
|
||
eventStream.merge(tasks).on('end', done); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use merge-stream instead. |
||
}); | ||
}); | ||
|
||
/** | ||
* First bundle, then serve from the ./app directory | ||
*/ | ||
gulp.task('default', ['bundle'], function () { | ||
browserSync.init({ | ||
server: "./app" | ||
server: './app' | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
## Installation/Usage: | ||
|
||
To try this example, follow these 4 simple steps. | ||
To try this example, follow these 4 simple steps. | ||
|
||
**Step 1**: Clone this entire repo | ||
```bash | ||
|
@@ -41,49 +41,71 @@ var watchify = require('watchify'); | |
var exorcist = require('exorcist'); | ||
var browserify = require('browserify'); | ||
var browserSync = require('browser-sync').create(); | ||
|
||
// Input file. | ||
watchify.args.debug = true; | ||
var bundler = watchify(browserify('./app/js/app.js', watchify.args)); | ||
|
||
// Babel transform | ||
bundler.transform(babelify.configure({ | ||
sourceMapRelative: 'app/js' | ||
})); | ||
|
||
// On updates recompile | ||
bundler.on('update', bundle); | ||
|
||
function bundle() { | ||
|
||
gutil.log('Compiling JS...'); | ||
|
||
return bundler.bundle() | ||
.on('error', function (err) { | ||
gutil.log(err.message); | ||
browserSync.notify("Browserify Error!"); | ||
this.emit("end"); | ||
}) | ||
.pipe(exorcist('app/js/dist/bundle.js.map')) | ||
.pipe(source('bundle.js')) | ||
.pipe(gulp.dest('./app/js/dist')) | ||
.pipe(browserSync.stream({once: true})); | ||
} | ||
var glob = require('glob'); | ||
var path = require('path'); | ||
var mkdirp = require('mkdirp'); | ||
var eventStream = require('event-stream'); | ||
|
||
/** | ||
* Gulp task alias | ||
* Creating multiple bundles with Watchify | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Watchify -> watchify |
||
*/ | ||
gulp.task('bundle', function () { | ||
return bundle(); | ||
gulp.task('bundle', function (done) { | ||
glob('./app/js/{app.js,worker/worker.js}', {}, function (err, files) { | ||
if (err) { | ||
done(err); | ||
} | ||
|
||
var tasks = files.map(function (entry) { | ||
var relative = path.relative('./app/js', entry); | ||
|
||
// A workaround for exorcist issue, | ||
// where exorcist fails silently when the output dir does not exist | ||
// see https://github.com/thlorenz/exorcist/issues/18 | ||
// and https://github.com/thlorenz/exorcist/pull/19 | ||
var sourceMapPath = './app/js/dist/' + relative + '.map'; | ||
mkdirp.sync(path.dirname(sourceMapPath)); | ||
|
||
// Input file. | ||
watchify.args.debug = true; | ||
var bundler = watchify(browserify(entry, watchify.args)); | ||
|
||
// Babel transform | ||
bundler.transform(babelify.configure({ | ||
sourceMapRelative: 'app/js' | ||
})); | ||
|
||
var bundle = function () { | ||
gutil.log('Compiling ' + entry + '...'); | ||
|
||
return bundler.bundle() | ||
.on('error', function (err) { | ||
gutil.log(err.message); | ||
browserSync.notify('Browserify Error!'); | ||
this.emit('end'); | ||
}) | ||
.pipe(exorcist(sourceMapPath)) | ||
.pipe(source(relative)) | ||
.pipe(gulp.dest('./app/js/dist')) | ||
.pipe(browserSync.stream({once: true})); | ||
} | ||
|
||
// On updates recompile | ||
bundler.on('update', bundle); | ||
|
||
return bundle(); | ||
}); | ||
|
||
eventStream.merge(tasks).on('end', done); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use merge-stream instead. |
||
}); | ||
}); | ||
|
||
/** | ||
* First bundle, then serve from the ./app directory | ||
*/ | ||
gulp.task('default', ['bundle'], function () { | ||
browserSync.init({ | ||
server: "./app" | ||
server: './app' | ||
}); | ||
}); | ||
``` | ||
|
||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK an empty object as the second object is optional.