Skip to content

Instantly share code, notes, and snippets.

@chrishalebarnes
Created January 8, 2020 19:19
Show Gist options
  • Save chrishalebarnes/92187b0ac0d6f5d7f84b9534aa03ad55 to your computer and use it in GitHub Desktop.
Save chrishalebarnes/92187b0ac0d6f5d7f84b9534aa03ad55 to your computer and use it in GitHub Desktop.
Browerify Example with Treeshaking and a Split Vendor Bundle
const browserify = require('browserify');
const fs = require('fs');
const hbsfy = require("hbsfy");
const treeshake = require('common-shakeify')
const factor = require('factor-bundle');
const path = require('path');
browserify({
entries: [ path.resolve('app/main.js'), path.resolve('app/another-entry.js') ],
paths: [ './node_modules','./app' ],
extensions: [ '.js', '.hbs' ]
})
.plugin(factor, { outputs: [ 'dist/main.js', 'dist/another-entry.js' ] })
.transform(hbsfy.configure({ extensions: [ 'hbs' ] }))
.transform('babelify')
.plugin(treeshake)
.bundle().pipe(fs.createWriteStream(process.cwd() + '/dist/vendor.js'));
node build.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment