Browserify and factor-bundle producing only one file
I have an application with several page specific js files and I am trying to use factor package to generate a generic js file with their common dependencies. So far, I can only get the browser and factor package to create one file (common.js) that contains all my js (like a normal browser package). Here is my gulp task:
gulp.task('browserify', function() {
return browserify({
entries: ['./app/client/page1.coffee', './app/client/page2.coffee'],
extensions: ['.coffee', '.jade'],
debug: true
}).plugin('factor-bundle', {
o: ['./public/js/page1.js', './public/js/page2.js']
})
.bundle()
.pipe(source('common.js'))
.pipe(gulp.dest('./public/js/'));
});
This only makes the common.js file in public / js and page1 and page2 not separate files (they are embedded in common.js).
Expected Results
public / js / page1.js (containing the page1.coffee code and any dependencies used only by
page1.coffee ) public / js / page2.js (containing the page2.coffee code and any dependencies used only by page2.coffee)
public /js/common.js (containing the dependencies shared by page1.coffee and page2.coffee)
Removing .plugin (...)
If I .plugin(...)
remove the modules inside common.js are in a different order, but the byte-for-byte is the same size as when .plugin(...)
.
Module information
Browserify (5.9.3)
Factor Bundle (2.1.0)
Vinyl Stream Source (0.1.1)
Gulp (3.8.7)
source to share
I ran into a similar problem and raised a question about the github factor account:
https://github.com/substack/factor-bundle/issues/29
There was no solution yet, but I found a workaround.
Did you find that the modules are split into separate pages as expected if you launch the browser using the factor-bundle plugin from the command line?
This was my experience, in this case I am using gulp-shell as a workaround to run it as a gulp task:
var gulp = require('gulp')
var shell = require('gulp-shell')
gulp.task('browserify-shell', shell.task([
'browserify ./app/assets/js/main.js ./app/assets/js/search.js -p [ factor-bundle -o ./public/js/main.js -o ./public/js/search.js ] -o ./public/js/common.js'
]));
source to share