import path             from 'path';
import webpack          from 'webpack';
import merge            from 'webpack-merge';
import NpmInstallPlugin from 'npm-install-webpack-plugin';

const TARGET = process.env.npm_lifecycle_event;
const PATHS = {
  app: path.join(__dirname, 'app'),
  build: path.join(__dirname, 'build')
};

process.env.BABEL_ENV = TARGET;

const common = {

  entry: {
    app: [`${PATHS.app}/js/main.js`]
  },

  resolve: {
    extensions: ['', '.js']
  },

  output: {
    path: `${PATHS.build}/js/`,
    filename: 'bundle.js'
  },

  module: {
    loaders: [
      {
        include: PATHS.app,
        test: /\.s?css$/,
        loaders: ['style', 'css', 'sass']
      },
      {
        include: PATHS.app,
        test: /\.js$/,
        exclude: /node_modules/,
        loaders: ['babel?cacheDirectory']
      }
    ]
  }

};

const start = {

  devtool: 'eval-source-map',

  devServer: {
    contentBase: PATHS.build,
    historyApiFallback: true,
    hot: true,
    inline: true,
    progress: true,
    stats: 'errors-only',
    host: process.env.HOST,
    port: process.env.PORT
  },

  plugins: [
    new webpack.HotModuleReplacementPlugin(),
    new NpmInstallPlugin({
      save: false,
      saveDev: true
    })
  ]

};

let envConfig;

if ( TARGET === 'start'  || !TARGET ) {
  envConfig = start;
} else if ( TARGET === 'build' ) {
  envConfig = {};
}

export default merge(common, envConfig);

@@ -1248,16 +1248,176 @@
  %5D%0A%0A%7D;%0A%0A
+const build = %7B%0A%0A  plugins: %5B%0A    new webpack.optimize.UglifyJsPlugin(%7B%0A      compress: %7B drop_console: true %7D // eslint-disable-line camelcase%0A    %7D)%0A  %5D%0A%0A%7D;%0A%0A
 let envC
@@ -1538,10 +1538,13 @@
 g = 
-%7B%7D
+build
 ;%0A%7D%0A

add JS minification for build