import {resolve} from 'path';
import {
  optimize,
  DefinePlugin,
  HotModuleReplacementPlugin,
  NamedModulesPlugin,
  NoEmitOnErrorsPlugin,
} from 'webpack';
import CleanPlugin from 'clean-webpack-plugin';
import CopyPlugin from 'copy-webpack-plugin';
import HTMLPlugin from 'html-webpack-plugin';
import BabiliPlugin from 'babili-webpack-plugin';
import OptimizeJSPlugin from 'optimize-js-plugin';
import ExtractTextPlugin, {extract} from 'extract-text-webpack-plugin';
import OfflinePlugin from 'offline-plugin';

const {ModuleConcatenationPlugin} = optimize;

const src = 'src';
const dest = 'app';
const clean = [dest];
const copy = [
  {
    from: 'static',
  },
];

export default function config({dev, devServer} = {}) {
  const env = dev ? 'development' : 'production';

  return {
    devtool: dev ? 'eval-source-map' : 'hidden-source-map',
    entry: [
      ...dev
        ? [
          `webpack-dev-server/client?${devServer}`,
          'webpack/hot/only-dev-server',
          'react-hot-loader/patch',
        ]
        : [],
      'babel-polyfill',
      `./${src}/index.jsx`,
    ],
    output: {
      path: resolve(__dirname, dest),
      filename: `bundle${dev ? '' : '.[chunkhash]'}.js`,
    },
    module: {
      rules: [
        {
          test: /\.jsx?$/,
          include: resolve(__dirname, src),
          loader: 'babel-loader',
          options: {
            cacheDirectory: dev,
            forceEnv: env,
          },
        },
        {
          test: /\.css$/,
          include: resolve(__dirname, src),
          use: dev ? [
            'style-loader',
            {
              loader: 'css-loader',
              options: {
                sourceMap: true,
                modules: true,
                localIdentName: '[name]__[local]___[hash:base64:5]',
              },
            },
          ] : extract({
            fallback: 'style-loader',
            use: {
              loader: 'css-loader',
              options: {
                sourceMap: true,
                modules: true,
                localIdentName: '[name]__[local]___[hash:base64:5]',
              },
            },
          }),
        },
      ],
    },
    plugins: [
      new CleanPlugin(clean),
      new CopyPlugin(copy),
      new HTMLPlugin({
        template: `${src}/template.ejs`,
        inject: false,
        minify: {
          removeComments: true,
          collapseWhitespace: true,
          minifyCSS: true,
          minifyJS: true,
        },
      }),
      new DefinePlugin({
        'process.env.NODE_ENV': JSON.stringify(env),
      }),
      ...dev
        ? [
          new HotModuleReplacementPlugin(),
          new NamedModulesPlugin(),
          new NoEmitOnErrorsPlugin(),
        ]
        : [
          new ModuleConcatenationPlugin(),
          new BabiliPlugin(),
          new OptimizeJSPlugin(),
          new ExtractTextPlugin({
            filename: `style${dev ? '' : '.[contenthash]'}.css`,
            allChunks: true,
          }),
          new OfflinePlugin(),
        ],
    ],
    resolve: {
      extensions: ['.js', '.jsx', '.json'],
    },
  };
}

@@ -1559,21 +1559,35 @@
 use: dev
+%0A           
  ? %5B%0A
+  
         
@@ -1610,34 +1610,38 @@
 r',%0A            
+ 
+ 
 %7B%0A
+  
               lo
@@ -1652,32 +1652,34 @@
 : 'css-loader',%0A
+  
               op
@@ -1695,32 +1695,34 @@
                 
+  
 sourceMap: true,
@@ -1730,32 +1730,34 @@
                 
+  
 modules: true,%0A 
@@ -1747,32 +1747,34 @@
  modules: true,%0A
+  
                 
@@ -1832,35 +1832,39 @@
 ,%0A              
+  
 %7D,%0A
+  
             %7D,%0A 
@@ -1872,17 +1872,31 @@
         
-%5D
+  %5D%0A           
  : extra
@@ -1900,16 +1900,18 @@
 tract(%7B%0A
+  
         
@@ -1948,24 +1948,26 @@
             
+  
 use: %7B%0A     
@@ -1967,32 +1967,34 @@
 %7B%0A              
+ 
+ 
 loader: 'css-loa
@@ -2005,32 +2005,34 @@
 ,%0A              
+  
 options: %7B%0A     
@@ -2018,32 +2018,34 @@
      options: %7B%0A
+  
                 
@@ -2069,32 +2069,34 @@
                 
+  
 modules: true,%0A 
@@ -2086,32 +2086,34 @@
  modules: true,%0A
+  
                 
@@ -2157,32 +2157,51 @@
 ash:base64:5%5D',%0A
+                %7D,%0A
               %7D,
@@ -2203,29 +2203,16 @@
    %7D,%0A  
-          %7D,%0A
         

Correct codestyle