let webpack = require('webpack');
let HtmlWebpackPlugin = require('html-webpack-plugin');
let autoprefixer = require('autoprefixer');
let atl = require('awesome-typescript-loader');

let path = require('path');

module.exports = function (env) {
  function isProd() {
    return env === 'prod';
  }

  let config = {
    entry: {
      globals: [
        'core-js/es6',
        'core-js/es7/reflect',
        'zone.js/dist/zone',
        'tslib'
      ],
      main: './src/main.ts'
    },
    output: {
      path: path.resolve(__dirname, 'dist'),
      filename: isProd() ? '[name].[chunkhash:7].bundle.js' : '[name].bundle.js',
      sourceMapFilename: isProd() ? undefined : '[name].map',
      chunkFilename: isProd() ? '[id].[chunkhash:7].chunk.js' : '[id].chunk.js'
    },
    resolve: {
      extensions: ['.ts', '.js']
    },
    module: {
      rules: [
        {
          test: /\.ts$/,
          loaders: [
            {
              loader: 'awesome-typescript-loader',
              query: {
                useForkChecker: true
              }
            },
            'angular2-template-loader'
          ],
          exclude: [/\.(spec|e2e)\.ts$/]
        },
        { test: /\.html$/, loader: 'raw-loader' },
        { test: /\.css$/, loaders: ['raw-loader', 'postcss-loader'] },
        { test: /\.less$/, loaders: ['raw-loader', 'postcss-loader', 'less-loader'] },
        { test: /\.scss$/, loaders: ['raw-loader', 'postcss-loader', 'sass-loader'] }
      ]
    },
    plugins: [
      new webpack.LoaderOptionsPlugin({
        debug: !isProd(),
        minimize: isProd(),
        options: {
          postcss: function () {
            return [autoprefixer];
          }
        }
      }),
      new webpack.DefinePlugin({
        ENV: JSON.stringify(env)
      }),
      new webpack.optimize.CommonsChunkPlugin({ name: 'globals' }),
      new HtmlWebpackPlugin({
        template: './src/index.html',
        chunksSortMode: 'dependency'
      }),
      new atl.ForkCheckerPlugin(),

      // workarround
      new webpack.ContextReplacementPlugin(
        /angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
        path.resolve(__dirname, 'src')
      )
    ],
    devServer: {
      port: 9000,
      contentBase: './src',
      historyApiFallback: true
    },
    node: {
      fs: 'empty',
      global: true,
      crypto: 'empty',
      process: true,
      module: false,
      clearImmediate: false,
      setImmediate: false
    }
  };

  if (isProd()) {
    //config.plugins.push(new webpack.optimize.DedupePlugin());
    config.plugins.push(new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } }));
  } else {
    config.devtool = 'source-map';
    config.entry.globals.push('zone.js/dist/long-stack-trace-zone');
  }

  return config;
};

@@ -205,16 +205,295 @@
 ath');%0A%0A
+const postcssLoader = %7B%0A  loader: 'postcss-loader',%0A  options: %7B%0A    plugins: function () %7B%0A      return %5B%0A        require('autoprefixer')%0A      %5D;%0A    %7D%0A  %7D%0A%7D;%0A%0Aconst awesomeTypescriptLoader = %7B%0A  loader: 'awesome-typescript-loader',%0A  query: %7B%0A    useForkChecker: true%0A  %7D%0A%7D;%0A%0A
 module.e
@@ -1145,26 +1145,16 @@
        %7B
-%0A         
  test: /
@@ -1160,26 +1160,16 @@
 /%5C.ts$/,
-%0A         
  loaders
@@ -1175,55 +1175,16 @@
 s: %5B
-%0A            %7B%0A              loader: '
 awesome
--t
+T
 ypes
@@ -1192,120 +1192,15 @@
 ript
--l
+L
 oader
-',%0A              query: %7B%0A                useForkChecker: true%0A              %7D%0A            %7D,%0A           
+,
  'an
@@ -1226,31 +1226,10 @@
 der'
-%0A          %5D,%0A         
+%5D,
  exc
@@ -1255,24 +1255,16 @@
 )%5C.ts$/%5D
-%0A       
  %7D,%0A    
@@ -1360,32 +1360,29 @@
 oader', 
-'
 postcss
--l
+L
 oader
-'
 %5D %7D,%0A   
@@ -1429,32 +1429,29 @@
 oader', 
-'
 postcss
--l
+L
 oader
-'
 , 'less-
@@ -1513,32 +1513,29 @@
 oader', 
-'
 postcss
--l
+L
 oader
-'
 , 'sass-
@@ -1671,118 +1671,8 @@
 od()
-,%0A        options: %7B%0A          postcss: function () %7B%0A            return %5Bautoprefixer%5D;%0A          %7D%0A        %7D
 %0A   

update webpack.config.js