Closed jurpy closed 9 years ago
Can you confirm the version of factor-bundle
in your project is 2.1.1?
You can also test within this repository:
$ cd test/deps
$ mkdir bundle
$ browserify x.js y.js -p [ ../../ -o bundle/x.js -o bundle/y.js ] -o bundle/common.js
This produces the three files with the expected outputs.
I have now got this working from the command line. Browserify was installed globally at 5.9.1 and after updating to 5.10.1 I got the three files as expected.
I still can't get it to work as expected when using Gulp though. I found someone that looks like they're having the same issue:
http://stackoverflow.com/questions/25280457/browserify-and-factor-bundle-producing-only-one-file
My gulp task is very similar to this one and I'm having the same problem of just a common.js file being produced.
Any help would be very appreciated! Thanks
@jrp90 in your example, does page1 or page2 require the other page?
No, both require 2 modules I want to be in the common js file and each one requires another page specific module I want to be in its own file.
The strange thing is it works as expected on my files if I use the command line but not when using my Gulp task.
Works:
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
Doesn't work:
var gulp = require('gulp');
var browserify = require('browserify');
var sourceStream = require('vinyl-source-stream');
var factor = require('factor-bundle');
gulp.task('browserify', function(){
return browserify({
entries: ['./app/assets/js/main.js', './app/assets/js/search.js'],
})
.plugin(factor, {
o: ['./public/js/main.js', './public/js/search.js']
})
.bundle()
.pipe(sourceStream('common.js'))
.pipe(gulp.dest('./public/js/'));
});
I seem to be having the same issue. It also works find from the command line, but not from gulp.
I have a workaround for now if you need one - just use the gulp-shell plugin to run the 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'
]));
I have the same issue as well
@jrp90 Ya, I ended up using the same workaround. Not ideal, but what factor-bundle does is fantastic enough to make it worth while.
Bummer this isn't worked out as a plugin as its not deployable via heroku now unless a custom build pack is created specific to the project.
Any ideas on when this might be fixed?
Same problem here. Thanks @jrp90 for the workaround.
JFYI I had the same issue. The workaround I found is usage of full paths + duplicate entries
property in factor-bundle plugin options:
browserify({
entries: ['c:/project/auth-logon/index.js', 'c:/project/views/model-create/index.js']
})
.plugin(factor, {
entries: ['c:/project/auth-logon/index.js', 'c:/project/views/model-create/index.js'],
o: ['c:/project/build/auth-logon.js', 'c:/project/build/model-create.js']
})
.bundle()
.pipe(source('common.js'))
.pipe(gulp.dest(buildPath));
It appers that second entries
is required to avoid TypeError: Arguments to path.resolve must be strings
.
My factor-bundle is 2.2.1 and browserify 5.11.2.
@mikalai-silivonik Nice ! Your workaround works for me and is a lot better than the gulp-shell solution.
Possibly the fix in factor-bundle core would be to path.resolve()
the arguments.
I can also confirm that this solution worked for me.
@substack Ya, my solution was mapping path.resolve
. Worked like a charm.
Awesome! This fixed my problem, too... especially @defrex 's suggestion to path.resolve the entries and output,
(function() {
'use strict';
var browserify = require('browserify');
var factor = require('factor-bundle');
var fs = require('fs');
var path = require('path');
var e = [path.resolve('./app/scripts/kioskAPI-gateway.js'),
path.resolve('./app/scripts/backoffice.js')];
var o = [path.resolve('./k.js'),
path.resolve('./b.js')];
var b = browserify();
b.add(e);
b.plugin(factor, {
e: e,
o: o
});
b.bundle().pipe(fs.createWriteStream('./c.js'));
}());
Now, on to adding bromote for the runtime-only scripts...
I'll patch this up, and look into why we aren't getting entries from browserify properly.
Don't know if I am doing something wrong or else, but I have the same problem even with a command line. So:
I have explicitly installed browserify@5.10.1 and factor-bundle@2.1.1, both globally (-g flag). Then I have created a directory with 5 files: x.js
console.log("X!");
y.js
console.log("Y!");
xy.js
console.log("XY!");
a.js
require('./x.js');
require('./xy.js');
and b.js
require('./y.js');
require('./xy.js');
Then I run in command line
browserify a.js b.js -p [ factor-bundle -o ba.js -o bb.js ] -o bcommon.js
And get only the "bcommon.js" file with x,y and xy all bundled into it.
@DenMesh I just tried your test case with browserify@6.2.0
and factor-bundle@2.3.2
and ba.js, bb.js and bcommon.js were created.
A fix for this I believe was included with 2.2.4, added by @substack.
Not sure whether this is an issue or just something I'm doing wrong or misunderstanding.
I'm trying to use factor-bundle to split my javascript into bundles for common and page-specific javascript but I can't even get the example given in the readme to work.
When I create the files x.js, y.js etc and run factor-bundle as a browserify plugin:
I just get the following output in bundle/common.js as the only file. I was expecting only the common modules to be present here and additional x.js and y.js files?
Browserify version 5.9.3 Factor-bundle version 2.1.1