const webpack = require('webpack');
const merge = require('webpack-merge');
const git = require('git-rev-sync');
const baseConfig = require('./base.config');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');

const Webpack_isomorphic_tools_plugin = require('webpack-isomorphic-tools/plugin');
const webpack_isomorphic_tools_plugin = new Webpack_isomorphic_tools_plugin(
    require('./webpack-isotools-config')
);

module.exports = merge(baseConfig, {
    mode: 'production',
    plugins: [
        new webpack.DefinePlugin({
            'process.env': {
                BROWSER: JSON.stringify(true),
                NODE_ENV: JSON.stringify('production'),
                // FIXME this requires we put .git into the docker image :(
                VERSION: JSON.stringify(git.tag()),
            },
            global: {
                TYPED_ARRAY_SUPPORT: JSON.stringify(false),
            },
        }),
        webpack_isomorphic_tools_plugin,
        new MiniCssExtractPlugin({
            filename: '[name].[hash].css',
            chunkFilename: '[id].[hash].css',
        }),
        process.env.ANALYZE_BUNDLE
            ? new (require('webpack-bundle-analyzer').BundleAnalyzerPlugin)()
            : null,
    ],
    module: {
        rules: [
            {
                test: /\.(sa|sc|c)ss$/,
                use: [
                    MiniCssExtractPlugin.loader,
                    'css-loader',
                    {
                        loader: 'postcss-loader',
                        options: {
                            plugins: () => [
                                require('autoprefixer')({
                                    browsers: ['> 1%', 'last 2 versions'],
                                }),
                            ],
                        },
                    },
                    'sass-loader',
                ],
            },
        ],
    },
    optimization: {
        minimizer: [
            // in production mode webpack 4 use own uglify
            new UglifyJsPlugin({
                cache: true,
                parallel: true,
                sourceMap: false,
            }),
            new OptimizeCSSAssetsPlugin({
                cssProcessorOptions: {
                    safe: true,
                }
            }),
        ],
    },
});

@@ -1245,49 +1245,10 @@
     
-process.env.ANALYZE_BUNDLE%0A            ? 
+//
 new 
@@ -1311,28 +1311,8 @@
 )()%0A
-            : null,%0A
     

fix BundleAnalyzerPlugin