/**
 * @yag/is-array
 *
 * @copyright Copyright (c) 2017 - 2018, Yassel Avila Gil (http://yasselavila.com)
 * @license   BSD 3 Clause (see LICENSE.txt)
 * @link      https://github.com/yasselavila/js-is-array
 */

const { env } = require('process');
const path = require('path');

const { EnvironmentPlugin, LoaderOptionsPlugin } = require('webpack');
const ModuleConcatenationPlugin = require('webpack/lib/optimize/ModuleConcatenationPlugin');
const { CheckerPlugin } = require('awesome-typescript-loader');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');

/* Env */
const nodeEnv = env.NODE_ENV || 'production';
const isProd = ('production' === nodeEnv);

/* Plugins */
const plugins = [
  /* Check and emit types in a separate process */
  new CheckerPlugin(),
  /* Make sure all dependencies are built in production mode */
  new EnvironmentPlugin({
    NODE_ENV: nodeEnv,
    DEBUG: !isProd
  }),
  /* Enable module concatenation */
  new ModuleConcatenationPlugin(),
  /* Enable minify */
  new LoaderOptionsPlugin({
    minimize: isProd,
    debug: !isProd
  })
];

/* Minify the ouput */
if (isProd) {
  plugins.push(
    new UglifyJsPlugin({
      uglifyOptions: {
        ecma: 5,
        ie8: true,
        output: {
          comments: false,
          beautify: false
        }
      }
    })
  );
}

/*
 * Export config
 */
module.exports = {
  entry: {
    'isarray': path.resolve('src/index')
  },
  output: {
    path: path.resolve('dist/bundles'),
    filename: '[name].umd.bundle.js',
    sourceMapFilename: '[name].umd.bundle.js.map',
    chunkFilename: '[name].umd.[chunk].js',
    libraryTarget: 'umd',
    pathinfo: !isProd
  },
  resolve: {
    extensions: ['.ts', '.tsx']
  },
  module: {
    loaders: [
      {
        test: /\.tsx?$/,
        loader: 'awesome-typescript-loader'
      }
    ]
  },
  plugins: plugins
};

@@ -1361,16 +1361,63 @@
 rts = %7B%0A
+  mode: isProd ? 'production' : 'development',%0A
   entry:
@@ -1504,14 +1504,28 @@
 lve(
+__dirname, 
 'dist
-/
+', '
 bund
@@ -1783,22 +1783,20 @@
 : %7B%0A    
-loader
+rule
 s: %5B%0A   

Update Webpack config