-
Star
(474)
You must be signed in to star a gist -
Fork
(84)
You must be signed in to fork a gist
-
-
Save danharper/3ca2273125f500429945 to your computer and use it in GitHub Desktop.
var gulp = require('gulp'); | |
var sourcemaps = require('gulp-sourcemaps'); | |
var source = require('vinyl-source-stream'); | |
var buffer = require('vinyl-buffer'); | |
var browserify = require('browserify'); | |
var watchify = require('watchify'); | |
var babel = require('babelify'); | |
function compile(watch) { | |
var bundler = watchify(browserify('./src/index.js', { debug: true }).transform(babel)); | |
function rebundle() { | |
bundler.bundle() | |
.on('error', function(err) { console.error(err); this.emit('end'); }) | |
.pipe(source('build.js')) | |
.pipe(buffer()) | |
.pipe(sourcemaps.init({ loadMaps: true })) | |
.pipe(sourcemaps.write('./')) | |
.pipe(gulp.dest('./build')); | |
} | |
if (watch) { | |
bundler.on('update', function() { | |
console.log('-> bundling...'); | |
rebundle(); | |
}); | |
} | |
rebundle(); | |
} | |
function watch() { | |
return compile(true); | |
}; | |
gulp.task('build', function() { return compile(); }); | |
gulp.task('watch', function() { return watch(); }); | |
gulp.task('default', ['watch']); |
@FranciscoG yes you are right! maybe it was needed since OP created this config based JS function instead gulp task. I have similar working configuration like yours at https://github.com/yeomann/GulPress/blob/master/gulpfile.js
Here's my take on it, hacked, slashed and smashed to bundle and watch multiple files working right. :)
https://gist.github.com/nicekiwi/ca575492dfd83504aced26892c559d58
More info on that in the gulp recipes here too:
https://github.com/gulpjs/gulp/blob/master/docs/recipes/browserify-multiple-destination.md
Here is mine, it does uglify & sourcemaps. It uses watchify for increment builds plus livereload to notify the browser.
https://gist.github.com/luv2code/77ddbc79c02d40194f929841d0696ebc
Thanks a lot. This works great.
However I added a return
statement on line 13
and 29
to show that the build task is completed
Finished 'build' after 749 ms
;
However, still, the batch process is not ending. I still have to press CTRL+C
to exit this process. :\
can we see the package.json of these?
question,
Why does anyone need watchify at all if you're already using gulp that comes with its own file watching built in?
I need to test this out but I believe you could rewrite the whole gulpfile to this: