max-scopp
2/2/2016 - 3:57 AM

How to exclude development/test code from production builds in 30 seconds with Webpack

How to exclude development/test code from production builds in 30 seconds with Webpack

webpack.config.js

var webpack = require('webpack');

var featureFlagsPlugin = new webpack.DefinePlugin({
  __DEV__: !!process.env.DEV,
  __RELEASE__: !!process.env.RELEASE
});

module.exports = {
  entry: {
    app: './index.js'
  },
  
  // ...
  
  plugins: [featureFlagsPlugin]
};

index.js

console.log('Hello from your library');

if (__DEV__) {
  console.log('in __DEV__ mode');
}

if (__RELEASE__) {
  console.log('in __RELEASE__ mode');
}
$ webpack 
$ DEV=1 webpack 
$ RELEASE=1 webpack 

Windows

> webpack
> set DEV=1 && webpack 
> set RELEASE=1 && webpack