• wincent's avatar
    Change __DEV__ handling to avoid need for process polyfill · 57e67f0b
    wincent authored
    Get rid of babel-plugin-dev-expression, which changes:
      if (__DEV__) { /* ... */ }
      if (process.env.NODE_ENV !== 'production') { /* ... */ }
    in favor of babel-plugin-minify-replace, which changes it to:
      if (true) { /* ... */ }
      if (false) { /* ... */ }
    depending on the config.
    Needless to say, Uglify will strip out the latter as dead-code in the
    webpack build.
    Configs, then, are:
    - .babelrc: this is used when evaluating gulpfile.babel.js or running a
      script like src/server/main.js with babel-node; this only happens in
      development (in production the dist build is used instead), so we can
      set __DEV__ to true. The one place inside gulpfile.babel.js that
      itself had an `if (__DEV__)` check is replaced with a check for
      `process.env.NODE_ENV !== 'production'` so that we can maintain the
      dynamic behavior.
    - `babelOptions` in gulpfile.babel.js: these are used when making the
      "dist" (production) build, so __DEV__ is set to false.
    - webpack.config.js: __DEV__ is set to true.
    - webpack.production.config.js: __DEV__ is set to false.
    Note, we no longer need the "devFallback" file because __DEV__ is now
    always set, either by Babel or by webpack.
    Omitting the process polyfill reduces the bundle from about 524,458
    bytes to 500,352 bytes, pre-gzip.
    In order to dispense with the process polyfill, I pass `node: false` in
    the production build and also make sure that the `unhandledRejection`
    file only tries to access `process` in node, not in the browser.
    (Browsers may support an "unhandledrejection" even, but support for it
    seems pretty thin at this time.)
.babelrc 439 Bytes