How to use browserify - 10 common examples

To help you get started, we’ve selected a few browserify examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mattdesl / budo / index.js View on Github external
var argv = parseArgs(args, opts)

  // if no stream is specified, default to stdout
  if (argv.stream !== false) {
    argv.stream = /^win/.test(process.platform) ? process.stdout : stdoutStream
  }

  var entries = argv._
  delete argv._

  argv.browserifyArgs = argv['--']
  delete argv['--']

  if (argv.version) {
    console.log('budo v' + require('./package.json').version)
    console.log('browserify v' + require('browserify/package.json').version)
    console.log('watchify v' + require('watchify-middleware').getWatchifyVersion())
    return null
  }

  if (argv.help) {
    var help = require('path').join(__dirname, 'bin', 'help.txt')
    require('fs').createReadStream(help)
      .pipe(process.stdout)
    return null
  }

  if (argv.outfile) {
    console.error(color.yellow('WARNING'), '--outfile has been removed in budo@3.0')
  }

  if (typeof argv.port === 'string') {
github freeCodeCamp / freeCodeCamp / unpack.js View on Github external
fs.mkdirp(unpackedDir, err => {
    if (err && err.code !== 'EEXIST') {
      console.log(err);
      throw err;
    }

    let unpackedFile = path.join(__dirname, 'unpacked.js');
    let b = browserify(unpackedFile).bundle();
    b.on('error', console.error);
    let unpackedBundleFile = path.join(unpackedDir, 'unpacked-bundle.js');
    const bundleFileStream = fs.createWriteStream(unpackedBundleFile);
    bundleFileStream.on('finish', () => {
      console.log('Wrote bundled JS into ' + unpackedBundleFile);
    });
    bundleFileStream.on('pipe', () => {
      console.log('Writing bundled JS...');
    });
    bundleFileStream.on('error', console.error);
    b.pipe(bundleFileStream);
    // bundleFileStream.end();  // do not do this prematurely!
  });
}
github vespakoen / extendscriptkit-boilerplate / scripts / actions.js View on Github external
function bundleJs() {
  // start the build process for index.js (for ES6/7 support in CEF)
  require('browserify')(jsEntry, {
    debug: false,
    plugin: [
      [require('prependify'), 'nodeRequire = require;']
    ]
  })
  .bundle(function (err, bundle) {
    if (err) {
      console.error(err.stack)
      return
    }
    fs.writeFileSync(jsBundle, bundle)
    const result = uglifyJS.minify([jsBundle])
    fs.writeFileSync(jsBundle, result.code)
  })
}
github learningequality / studio / build.js View on Github external
{ global: true }
);

if (watch) {
  var watchify = require('watchify');
  browserify.plugin(watchify,
    { // watchify options
      verbose: true,
      poll: 1000,
      ignoreWatch: '**/node_modules/**',
    }
  );

  infoLog('Starting watcher');

  browserify.on('update', function (ids) {
    infoLog('files changed, bundle updated');
    _.each(ids, function(id) {infoLog(id + ' changed');});
    createBundles(browserify, bundles);
  });

  browserify.on('log', infoLog);

  browserify.on('error', function(error) {
    errLog(error);
    this.emit('end');
  });
}

createBundles(browserify, bundles);
github learningequality / studio / build.js View on Github external
{ // watchify options
      verbose: true,
      poll: 1000,
      ignoreWatch: '**/node_modules/**',
    }
  );

  infoLog('Starting watcher');

  browserify.on('update', function (ids) {
    infoLog('files changed, bundle updated');
    _.each(ids, function(id) {infoLog(id + ' changed');});
    createBundles(browserify, bundles);
  });

  browserify.on('log', infoLog);

  browserify.on('error', function(error) {
    errLog(error);
    this.emit('end');
  });
}

createBundles(browserify, bundles);
github gchudnov / inkjet / config / browserify.js View on Github external
gulp.task('script', () => {

  const isProduction = (process.env.NODE_ENV === 'production');

  const bundleConfig = {
    name: 'inkjet',
    entries: [`./src/index.js`], // require.resolve('babel-polyfill'),
    dest: './dist',
    outputName: `inkjet${isProduction ? '.min' : ''}.js`,
    isUglify: isProduction,
  };

  let bundler = browserify({
    entries: bundleConfig.entries,
    insertGlobals: false,
    detectGlobals: true,
    standalone: bundleConfig.name,
    debug: false
  });

  let bundle = () => {
    return bundler
      .bundle()
      .on('error', handleErrors)
      .pipe(source(bundleConfig.outputName))
      .pipe(header(banner, { pkg: pkg }))
      .pipe(gulpIf(bundleConfig.isUglify, uglify()))
      .pipe(gulp.dest(bundleConfig.dest))
  };
github learningequality / studio / build.js View on Github external
// now that we've collected the bundle modules we need, set up browserify
var browserify = browserify({
  paths: modulePaths,
  cache: {},
  packageCache: {},
  debug: true,
});

// all the files are being included inplicitly by watching the modules we hand-write
_.each(bundles,
  function(item) {
    browserify.add(item.bundle, {expose: item.alias});
  }
);

browserify.transform(vueify);
// handlebars translation
browserify.transform(hbsfy);

browserify.transform(babelify);

// less translation
browserify.transform(lessify,
  { // less options
    global: true,
  }
);

browserify.transform(
  envify({
    NODE_ENV: prod ? 'production' : 'development',
  }),
github learningequality / studio / build.js View on Github external
paths: modulePaths,
  cache: {},
  packageCache: {},
  debug: true,
});

// all the files are being included inplicitly by watching the modules we hand-write
_.each(bundles,
  function(item) {
    browserify.add(item.bundle, {expose: item.alias});
  }
);

browserify.transform(vueify);
// handlebars translation
browserify.transform(hbsfy);

browserify.transform(babelify);

// less translation
browserify.transform(lessify,
  { // less options
    global: true,
  }
);

browserify.transform(
  envify({
    NODE_ENV: prod ? 'production' : 'development',
  }),
  { global: true }
);
github learningequality / studio / build.js View on Github external
);

browserify.transform(vueify);
// handlebars translation
browserify.transform(hbsfy);

browserify.transform(babelify);

// less translation
browserify.transform(lessify,
  { // less options
    global: true,
  }
);

browserify.transform(
  envify({
    NODE_ENV: prod ? 'production' : 'development',
  }),
  { global: true }
);

if (watch) {
  var watchify = require('watchify');
  browserify.plugin(watchify,
    { // watchify options
      verbose: true,
      poll: 1000,
      ignoreWatch: '**/node_modules/**',
    }
  );
github learningequality / studio / build.js View on Github external
packageCache: {},
  debug: true,
});

// all the files are being included inplicitly by watching the modules we hand-write
_.each(bundles,
  function(item) {
    browserify.add(item.bundle, {expose: item.alias});
  }
);

browserify.transform(vueify);
// handlebars translation
browserify.transform(hbsfy);

browserify.transform(babelify);

// less translation
browserify.transform(lessify,
  { // less options
    global: true,
  }
);

browserify.transform(
  envify({
    NODE_ENV: prod ? 'production' : 'development',
  }),
  { global: true }
);

if (watch) {