Watchify seems to ignore 'external' modules from other bundles and include them anyway. This doesn't happen the first time the bundle is created, maybe because the task is done by browserify and everything is okay.
This is my current gulp task:
var config = require('../config.json');
var packageManifest = require('../../package.json');
var watchify = require('watchify');
var gulp = require('gulp');
var browserify = require('browserify');
var uglify = require('gulp-uglify');
var gulpif = require('gulp-if');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var path = require('path');
var browserSync = require('browser-sync');
var paths = {
src: path.join(config.root.src, config.tasks.scripts.src, config.tasks.scripts.main),
dest: path.join(config.root.dest, config.tasks.scripts.dest)
};
var isProduction = process.env.NODE_ENV === 'production';
var deps = Object.keys(packageManifest.dependencies); //[ 'react', 'react-dom' ]
var customOpts = {
cache: {},
packageCache: {},
entries: paths.src,
debug: isProduction? false : true,
transform: [
['babelify', {presets: ['es2015', 'react']}]
]
};
var appBundle = browserify(customOpts);
appBundle.plugin(watchify);
appBundle.external(deps);
var buildApp = function() {
return appBundle
.bundle()
.on('error', console.log)
.pipe(source('main.js'))
.pipe(buffer())
.pipe( gulpif(isProduction, uglify()) )
.on('error', console.log)
.pipe(gulp.dest(paths.dest))
.pipe(browserSync.stream());
};
appBundle.on('update', buildApp);
gulp.task('scripts', buildApp);
The bundle is also minified for some strange reason, although I tried to remove uglify.
EDIT: Well, I don't know what happened but it seems resolved. I did nothing but shutting down the computer after opening this issue and now it works smoothly. Maybe it was something with gulp itself.
Watchify seems to ignore 'external' modules from other bundles and include them anyway. This doesn't happen the first time the bundle is created, maybe because the task is done by browserify and everything is okay. This is my current gulp task:
The bundle is also minified for some strange reason, although I tried to remove uglify.
EDIT: Well, I don't know what happened but it seems resolved. I did nothing but shutting down the computer after opening this issue and now it works smoothly. Maybe it was something with gulp itself.