Skip to content

Instantly share code, notes, and snippets.

@mattdesl
Last active August 9, 2019 13:21
Show Gist options
  • Select an option

  • Save mattdesl/57825db09d5193916cb3 to your computer and use it in GitHub Desktop.

Select an option

Save mattdesl/57825db09d5193916cb3 to your computer and use it in GitHub Desktop.

Revisions

  1. mattdesl revised this gist Jan 7, 2016. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions build.js
    Original file line number Diff line number Diff line change
    @@ -13,6 +13,7 @@ if (process.env.NODE_ENV === 'development') {
    // fast dev server
    require('budo')(entry, {
    serve: 'bundle.js',
    stream: process.stdout, // log requests in terminal
    live: true, // enable LiveReload
    browserify: bundleOpts
    });
  2. mattdesl revised this gist Jan 7, 2016. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion build.js
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,9 @@ if (process.env.NODE_ENV === 'development') {
    } else {
    // optimized production bundle
    require('browserify')(entry, bundleOpts)
    .transform('unreachable-branch-transform', { global: true }) // dead code elimination
    .transform('unreachable-branch-transform', { // dead code elimination
    global: true // so that it runs on dependencies, e.g. react, react-dom
    })
    .plugin('bundle-collapser/plugin') // smaller bundle size
    .bundle()
    .pipe(process.stdout);
  3. mattdesl revised this gist Jan 7, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion build.js
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,7 @@ if (process.env.NODE_ENV === 'development') {
    } else {
    // optimized production bundle
    require('browserify')(entry, bundleOpts)
    .transform('unreachable-branch-transform') // dead code elimination
    .transform('unreachable-branch-transform', { global: true }) // dead code elimination
    .plugin('bundle-collapser/plugin') // smaller bundle size
    .bundle()
    .pipe(process.stdout);
  4. mattdesl revised this gist Jan 7, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion about.md
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@ Small script for development + builds with browserify.
    Uses `loose-envify` for faster inlining and `cross-env` to handle windows/unix shells.

    Dev features:
    - fast rebuidls w/ watchify, LiveReload, syntax errors in DOM, etc.
    - fast rebuilds w/ watchify, LiveReload, syntax errors in DOM, etc.

    Build features:
    - uglify, simple dead code elimination, optimized bundle.
  5. mattdesl renamed this gist Jan 7, 2016. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  6. mattdesl revised this gist Jan 7, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    ...
    "scripts": {
    "start": "cross-env NODE_ENV=development node tools/build.js",
    "build": "cross-env NODE_ENV=production node tools/build.js | uglifyjs -cm > app/bundle.js"
    "start": "cross-env NODE_ENV=development node build.js",
    "build": "cross-env NODE_ENV=production node build.js | uglifyjs -cm > app/bundle.js"
    }
    ...
  7. mattdesl revised this gist Jan 7, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions bundler.js
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@ var entry = 'index.js';

    // Some options shared in dev + prod
    var bundleOpts = {
    debug: true,
    debug: true, // inline source maps
    transform: [
    'babelify',
    'loose-envify'
    @@ -13,7 +13,7 @@ if (process.env.NODE_ENV === 'development') {
    // fast dev server
    require('budo')(entry, {
    serve: 'bundle.js',
    live: true,
    live: true, // enable LiveReload
    browserify: bundleOpts
    });
    } else {
  8. mattdesl revised this gist Jan 7, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion about.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    Script for development + build with browserify.
    Small script for development + builds with browserify.

    Uses `loose-envify` for faster inlining and `cross-env` to handle windows/unix shells.

  9. mattdesl revised this gist Jan 7, 2016. 1 changed file with 6 additions and 2 deletions.
    8 changes: 6 additions & 2 deletions about.md
    Original file line number Diff line number Diff line change
    @@ -2,8 +2,12 @@ Script for development + build with browserify.

    Uses `loose-envify` for faster inlining and `cross-env` to handle windows/unix shells.

    Dev features: fast rebuidls w/ watchify, LiveReload, syntax errors in DOM, etc.
    Build features: uglify, simple dead code elimination, optimized bundle.
    Dev features:
    - fast rebuidls w/ watchify, LiveReload, syntax errors in DOM, etc.

    Build features:
    - uglify, simple dead code elimination, optimized bundle.


    ```sh
    npm install --save-dev cross-env browserify budo babelify loose-envify bundle-collapser uglify-js unreachable-branch-transform
  10. mattdesl created this gist Jan 7, 2016.
    10 changes: 10 additions & 0 deletions about.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    Script for development + build with browserify.

    Uses `loose-envify` for faster inlining and `cross-env` to handle windows/unix shells.

    Dev features: fast rebuidls w/ watchify, LiveReload, syntax errors in DOM, etc.
    Build features: uglify, simple dead code elimination, optimized bundle.

    ```sh
    npm install --save-dev cross-env browserify budo babelify loose-envify bundle-collapser uglify-js unreachable-branch-transform
    ```
    26 changes: 26 additions & 0 deletions bundler.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    var entry = 'index.js';

    // Some options shared in dev + prod
    var bundleOpts = {
    debug: true,
    transform: [
    'babelify',
    'loose-envify'
    ]
    };

    if (process.env.NODE_ENV === 'development') {
    // fast dev server
    require('budo')(entry, {
    serve: 'bundle.js',
    live: true,
    browserify: bundleOpts
    });
    } else {
    // optimized production bundle
    require('browserify')(entry, bundleOpts)
    .transform('unreachable-branch-transform') // dead code elimination
    .plugin('bundle-collapser/plugin') // smaller bundle size
    .bundle()
    .pipe(process.stdout);
    }
    6 changes: 6 additions & 0 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    ...
    "scripts": {
    "start": "cross-env NODE_ENV=development node tools/build.js",
    "build": "cross-env NODE_ENV=production node tools/build.js | uglifyjs -cm > app/bundle.js"
    }
    ...