Skip to content

Banner string duplicates on watchify rebundle #1

Open
@cguinnup

Description

@cguinnup

Thanks for the plugin, I especially appreciate the source map support.

I'm adding a simple string banner and performing incremental rebundles with watchify. On the first bundling, everything is correct. After changing source code & triggering subsequent rebundles, there are suddenly duplicate instances of the banner string. This duplication causes an error when the script runs.

I believe my use of browserify-banner is correct:

let scriptBundler = browserify({
	entries: entry + '.js',
	basedir: buildDir,
	debug: devMode,  // Source maps!
	cache: {},         // For watchify's incremental bundling 
	packageCache: {},  // "
	fullPaths: false,  // "
	noParse: ['jquery'], // No require() in this big lib: save time & don't parse
	browserField: false,              // Makes bundle runnable in Node
	builtins: false,                  // "
	commondir: false,                 // "
	insertGlobalVars: {               // "
		Buffer: undefined,            // "
		'Buffer.isBuffer': undefined, // "
		global: undefined,            // "
		process: undefined            // "
	},								 
});

// Make the Node script runnable in the shell
let scriptHeader = '#!/usr/bin/env node\n';
if (devMode) {
	// Make Node show source code in stack traces
	scriptHeader += 'require("source-map-support").install();\n';
	scriptBundler.plugin(watchify);
}
scriptBundler.plugin(banner, {banner: scriptHeader});

// The rebundle process
const rebundle = function () {
	var start = Date.now();
	console.log('Bundling "' + entry + '"');
	return scriptBundler.bundle()
	  .pipe(vinylStream(entry))
	  .pipe(gulpif(!devMode && !argv['skip-minify'], vinylBuffer()))
	  .pipe(gulpif(!devMode && !argv['skip-minify'], uglify()))
  	  .pipe(chmod({ execute: true }))
	  .pipe(gulp.dest(distDir))
	  .pipe(notify(function() {
	  	console.log('Bundled  "' + entry + '" in ' + (Date.now() - start) / 1000 + ' s');
	  }));
};

// Watch for changes while developing
if (devMode) {
	scriptBundler.on('update', rebundle);
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions