Example: Multiple Environments

  • Webpkr lets you specify configuration items for all environments in the same configuration.

  • No need to duplicate configurations for multiple environments

const Stats = require( 'stats-webpack-plugin' );

context( projectDir )

entry( './src/index.js' )

output( () => {
  filename( 'bundle.js' )
  path$( 'dist' )
} )

// Included only when NODE_ENV=development
development( () => {
  devtool( 'cheap-module-source-map' )
  plugin( new Stats( 'stats.json', {
    chunkModules: true
  } ) )
} )

// Included only when NODE_ENV=production
production( () => {
  plugin( new webpack.optimize.UglifyJsPlugin( {
    mangle: true,
    compress: {
      screw_ie8: true,
      warnings: false,
    },
  } ) )

  plugin( new webpack.optimize.AggressiveMergingPlugin() )

  plugin( new webpack.optimize.MinChunkSizePlugin( {
    minChunkSize: 2048,
  } ) )
} )

Configure Webpack

Create a webpack.config.js in your project’s root and add:

const webpkr = require('webpkr');
module.exports = webpkr({projectDir: __dirname});