I've made a gulp task for browserify with babelify in my Angular project, which I'm developing in WebStorm. First of all, I should say, that this code does work perfectly.
My browserify bundle be like:
const appBundle = browserify({
entries: config.client.src.appModule, // main angular app file
debug: TRUE,
packageCache: {},
cache: {}
}).transform(babelify, {only: './src/client'}).on('log', gutil.log);
And my gulp.task be like:
gulp.task('browserify', ['jshint'], function () {
return appBundle.bundle()
.on('error', function (err) {
gutil.log('Browserify error: ' + gutil.colors.red(err.message));
})
.pipe(source('app.js')) // main dist file
.pipe(gulp.dest('./dist'));
});
The issue I can't understand at all:
My question was: Why is my gulp task not terminating after it is through with its job? I should always stop it manually by clicking square button in my WebStorm.
UPDATE 1
I've figured out that the problem is eliminated if I pass "browserify" bundle directly, without the variable appBundle. So the code turns to:
browserify({
entries: config.client.src.appModule, // main angular app file
debug: TRUE,
packageCache: {},
cache: {}
}).transform(babelify, {only: './src/client'}).on('log', gutil.log)
.bundle().on('error', function (err) {
gutil.log('Browserify error: ' + gutil.colors.red(err.message));
})
.pipe(source('app.js')) // main dist file
.pipe(gulp.dest('./dist'));
And it works! But the main hardship is that i'm using this appBundle in my watchify task, so I don't want to duplicate the bundle.
UPDATE 2
After a couple of hours I've figured out again, that's the issue was concerned with my watchify task. The hole code was like that:
const appBundle = browserify({
entries: config.client.src.appModule, // main js file
debug: TRUE,
packageCache: {},
cache: {}
}).transform(babelify, {only: './src/client'});
const b = watchify(appBundle);
function rebundle(bundler) {
return bundler
.bundle()
.on('error', function (err) {
gutil.log('Browserify error: ' + gutil.colors.red(err.message));
})
.pipe(source('app.js'))
.pipe(gulp.dest('./dist'));
}
gulp.task('watchify', function () {
rebundle(b);
b.on('update', function () {
rebundle(b)
});
b.on('log', gutil.log); // output build logs to terminal
});
gulp.task('browserify', ['jshint'], function () {
rebundle(appBundle);
});
And when I've put down declaration of the const b
into my watchify task, everything everything has started to work properly.
But the final question is: WHY IT HAS STARTED TO WORK?