browserify / factor-bundle

factor browser-pack bundles into common shared bundles
Other
400 stars 27 forks source link

Null characters, truncated files file size variance. #60

Closed treshugart closed 9 years ago

treshugart commented 9 years ago

Hey guys, several issues, but logging it as a single one because it might be related to the same thing.

First up, I noticed null characters being inserted into the built files. It inserts somewhere between 100k and 200k null chars. Where they are placed is always between the joining of two modules, but it's random which modules it's placed between.

null-char

Second, it seems the files vary in line length between consecutive builds with no modifications to the source:

12229-lines 8980-lines 12223

Third, sometimes this happens:

truncated

That's the end of the file. Notice the unexpected end of input, or truncated source. All of these things are reproducible in the fact that they happen, but where they happen is kinda random.

Here's my gulp build:

module.exports = function dist () {
    var files = glob.sync('./src/js/aui*.js');

    fs.removeSync('dist/aui/js');
    fs.mkdirsSync('dist/aui/js');

    return browserify({
            entries: files,
            externalRequireName: '__aui_require'
        })
        .transform(babelify.configure({
            blacklist: ['useStrict'],
            modules: 'common'
        }))
        .plugin(factorBundle, {
            outputs: files.map(function formatToDistPath (file) {
                return 'dist/aui/js/' + path.basename(file);
            })
        })
        .bundle(function afterBundle () {
            var concatFilter = gulpFilter([ 'aui-common.js', 'aui.js' ]);
            gulp.src('dist/aui/js/aui*.js')
                .pipe(concatFilter)
                .pipe(gulpConcat('aui.js'))
                .pipe(concatFilter.restore())
                .pipe(gulp.dest('dist/aui/js'));
        })
        .pipe(vinylSourceStream('aui-common.js'))
        .pipe(gulp.dest('dist/aui/js'))
        .on('error', error);
};

I'm using Browserify 9.0.3 and Factor Bundle 2.3.3. None of these issues occur when I use Browserify directly and compile to a single resource. Unfortunately that isn't an option for us right now.

The randomness is very disconcerting especially since there's no errors during compilation.

treshugart commented 9 years ago

Seems that if you move the stuff outside of the bundle callback things work a bit better. This means that .bundle() must get called prior to the streams being flushed.