var webpack = require('webpack');
var CleanPlugin = require('clean-webpack-plugin');
var production = process.env.NODE_ENV === 'production';
var exec = require('child_process').exec;

// Build the documentation
exec('npm run docs');

var plugins = [
  // Dev and production plugins
];

if (production) {
  plugins = plugins.concat([
    // Production only plugins

    // Cleanup the build/ folder before compiling production assets
    new CleanPlugin('build'),

    // Looks for similar chunks and files and merges them for better caching
    // by the user
    new webpack.optimize.DedupePlugin(),

    // Optimizes chunks and modules by how much they are used in your app
    new webpack.optimize.OccurenceOrderPlugin(),

    // This plugin prevents Webpack from creating chunks that would be
    // too small to be worth loading separately
    new webpack.optimize.MinChunkSizePlugin({
        minChunkSize: 51200, // ~50kb
    }),

    // This plugin minifies all the Javascript code of the final bundle
    new webpack.optimize.UglifyJsPlugin({
        mangle:   true,
        compress: {
            warnings: false, // Suppress uglification warnings
        },
    }),

    // Defines various variables that we can set to false
    // in production to avoid code related to them from being compiled
    // in our final bundle
    new webpack.DefinePlugin({
        __SERVER__:      !production,
        __DEVELOPMENT__: !production,
        __DEVTOOLS__:    !production,
        'process.env':   {
            BABEL_ENV: JSON.stringify(process.env.NODE_ENV),
        },
    }),
  ]);
}

module.exports = {
  debug: !production,
  // Source map generation
  devtool: production ? false : 'eval',
  entry: './src/main.js',
  output: {
    path: 'build',
    filename: 'genetic-sandbox.js'
  },
  plugins: plugins,
  module: {
    loaders: [
      {
        // Run all .js files through Babel
        test: /\.js$/,
        exclude: /(node_modules|bower_components)/,
        loader: 'babel',
        query: {
          presets: ['es2015']
        }
      },
      {
        // Load and immediately apply all CSS files
        test: /\.css$/,
        loader: 'style!css'
      }
    ]
  }
};

@@ -184,17 +184,176 @@
 %0A// 
-Build the
+Plugin to build the documentation%0Afunction DocumentationBuildPlugin(options) %7B %7D%0ADocumentationBuildPlugin.prototype.apply = function(compiler) %7B%0A  console.log('Building
  doc
@@ -362,17 +362,25 @@
 entation
-%0A
+...');%0A  
 exec('np
@@ -392,16 +392,18 @@
  docs');
+%0A%7D
 %0A%0Avar pl
@@ -1756,16 +1756,125 @@
 %0A  %5D);%0A%7D
+ else %7B%0A  // Development only plugins%0A  plugins = plugins.concat(%5B%0A    new DocumentationBuildPlugin()%0A  %5D);%0A%7D
 %0A%0Amodule

Build docs on webpack build