const webpack = require('webpack')
const path = require('path')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const VueLoaderPlugin = require('vue-loader/lib/plugin')

module.exports = {
  entry: './src/main.js',
  mode: 'development',
  output: {
    path: path.resolve(__dirname, 'build'),
    publicPath: '/build/',
    filename: 'bundle.js'
  },
  devtool: 'inline-source-map',
  devServer: {
    historyApiFallback: true
  },
  plugins: [
    new VueLoaderPlugin()
  ],
  resolve: {
    alias: {
      '~': path.resolve(__dirname, 'src/'),
      '~api': path.resolve(__dirname, 'src/api/'),
      '~assets': path.resolve(__dirname, 'src/assets/'),
      '~components': path.resolve(__dirname, 'src/components/'),
      '~config': path.resolve(__dirname, 'src/weblearn.config.js'),
      '~events': path.resolve(__dirname, 'src/events/'),
      '~pages': path.resolve(__dirname, 'src/pages/'),
      '~store': path.resolve(__dirname, 'src/store/'),
      '~topics': path.resolve(__dirname, 'src/topics/'),
      '~transformers': path.resolve(__dirname, 'src/transformers/'),
      '~util': path.resolve(__dirname, 'src/util/'),
      '~widgets': path.resolve(__dirname, 'src/widgets/')
    }
  },
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          loaders: {
            sass: 'vue-style-loader!css-loader!sass-loader?indentedSyntax',
            scss: 'vue-style-loader!css-loader!sass-loader'
          }
        }
      },
      {
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: /node_modules/
      },
      {
        test: /\.json$/,
        loader: 'json-loader'
      },
      {
        test: /\.(yml|yaml)$/,
        loader: 'json-loader!yaml-loader'
      },
      {
        test: /\.pug$/,
        loader: 'pug-plain-loader'
      },
      {
        test: /\.sass$/,
        loader: 'style-loader!css-loader!sass-loader?indentedSyntax'
      },
      {
        test: /\.scss$/,
        loader: 'style-loader!css-loader!sass-loader'
      },
      {
        test: /\.(png|jpg|gif|svg)$/,
        loader: 'file-loader',
        query: {
          name: '[name].[ext]?[hash]'
        }
      }
    ]
  }
}

if (process.env.NODE_ENV === 'production') {
  module.exports.mode = 'production'
  module.exports.plugins = (module.exports.plugins || []).concat([
    new CopyWebpackPlugin([
      { from: 'src/static' }
    ]),
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: '"production"'
      }
    }),
    new webpack.LoaderOptionsPlugin({
      minimize: true
    }),
    new webpack.optimize.OccurrenceOrderPlugin()
  ])
}

@@ -170,16 +170,170 @@
 plugin')
+%0Aconst BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin%0Aconst MomentLocalesPlugin = require('moment-locales-webpack-plugin')
 %0A%0Amodule
@@ -2410,12 +2410,51 @@
 ion'
+ %7C%7C process.env.NODE_ENV === 'analyzer'
 ) %7B%0A
-
   mo
@@ -2553,16 +2553,47 @@
 oncat(%5B%0A
+    new MomentLocalesPlugin(),%0A
     new 
@@ -2868,15 +2868,173 @@
 lugin()%0A
-
   %5D)
+%0A%0A  if(process.env.NODE_ENV === 'analyzer') %7B%0A    module.exports.plugins = (module.exports.plugins %7C%7C %5B%5D).concat(%5B%0A      new BundleAnalyzerPlugin()%0A    %5D)%0A  %7D
 %0A%7D%0A

Update webpack.config.js