<commit_before>'use strict'
process.env.NODE_ENV = 'production'
process.env.REACT_WEBPACK_ENV = 'dist'

const exec = require('child_process').execSync
const path = require('path')
const glob = require('glob')
const webpack = require('webpack')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const PurifyCSSPlugin = require('purifycss-webpack')
const ProgressPlugin = require('webpack/lib/ProgressPlugin')
const ManifestPlugin = require('webpack-manifest-plugin')
const OfflinePlugin = require('offline-plugin')
const PreloadWebpackPlugin = require('preload-webpack-plugin')
const LodashModuleReplacementPlugin = require('lodash-webpack-plugin')
const base = require('./webpack.base')
const config = require('./config')
const _ = require('./utils')

exec('rm -rf dist/')
base.devtool = 'cheap-source-map'
base.module.rules.push({
    test: /\.css$/,
    use: ExtractTextPlugin.extract({fallback:  'isomorphic-style-loader', use: 'css-loader'})
}, {
    test: /\.scss$/,
    use: ExtractTextPlugin.extract({
        fallback: 'isomorphic-style-loader',
        use: ['css-loader', 'sass-loader']
    })
})

// a white list to add dependencies to vendor chunk
base.entry.vendor = config.vendor
// use hash filename to support long-term caching
base.output.filename = '[name].[chunkhash:8].js'

// add webpack plugins
base.plugins.push(
    new ProgressPlugin(),
    new ExtractTextPlugin('[name].[chunkhash:8].css'),
    new webpack.DefinePlugin({'process.env.NODE_ENV': JSON.stringify('production')}),
    new LodashModuleReplacementPlugin,
    new webpack.optimize.UglifyJsPlugin({
        sourceMap: true,
        compress: {
            warnings: false
        },
        output: {
            comments: false
        }
    }),
    // extract vendor chunks
    new webpack.optimize.CommonsChunkPlugin({name: 'vendor', filename: 'vendor.[chunkhash:8].js'}),
    new PreloadWebpackPlugin({rel: 'preload', as: 'script', include: 'all'}),
    // remove unused css
    new PurifyCSSPlugin({
        // Give paths to parse for rules. These should be absolute!
        moduleExtensions: ['.jsx', '.html', '.js'],
        paths: glob.sync(
            path.join(__dirname, 'common/*.jsx'),
            path.join(__dirname, 'common/components/**/*.jsx'),
            path.join(__dirname, 'common/containers/**/*.jsx'),
            path.join(__dirname, 'common/containers/**/*.jsx'),
            path.join(__dirname, 'node_modules/semantic-ui-react/dist/**/*.js')
        )
    }),
    // For progressive web apps
    // create manifest
    new ManifestPlugin({fileName: 'manifest.json', cache: config.manifest}),
    // AppCache + ServiceWorkers
    new OfflinePlugin({
        relativePaths: false,
        safeToUseOptionalCaches: true,
        //    publicPath: '/',
        caches: {
            main: [
                'vendor.*.css', 'vendor.*.js'
            ],
            additional: [':externals:'],
            optional: [':rest:']
        },
        excludes: ['.htaccess'],
        AppCache: false,
        ServiceWorker: {
            events: true
        }
    })
)
// minimize webpack output<commit_msg>remove lodashReplacementPlugin, add some features for OfflinePlugin<commit_after>'use strict'
process.env.NODE_ENV = 'production'
process.env.REACT_WEBPACK_ENV = 'dist'

const exec = require('child_process').execSync
const path = require('path')
const glob = require('glob')
const webpack = require('webpack')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const PurifyCSSPlugin = require('purifycss-webpack')
const ProgressPlugin = require('webpack/lib/ProgressPlugin')
const ManifestPlugin = require('webpack-manifest-plugin')
const OfflinePlugin = require('offline-plugin')
const PreloadWebpackPlugin = require('preload-webpack-plugin')
const base = require('./webpack.base')
const config = require('./config')
const _ = require('./utils')

exec('rm -rf dist/')
base.devtool = 'cheap-source-map'
base.module.rules.push({
    test: /\.css$/,
    use: ExtractTextPlugin.extract({fallback:  'isomorphic-style-loader', use: 'css-loader'})
}, {
    test: /\.scss$/,
    use: ExtractTextPlugin.extract({
        fallback: 'isomorphic-style-loader',
        use: ['css-loader', 'sass-loader']
    })
})

// a white list to add dependencies to vendor chunk
base.entry.vendor = config.vendor
// use hash filename to support long-term caching
base.output.filename = '[name].[chunkhash:8].js'

// add webpack plugins
base.plugins.push(
    new ProgressPlugin(),
    new ExtractTextPlugin('[name].[chunkhash:8].css'),
    new webpack.DefinePlugin({'process.env.NODE_ENV': JSON.stringify('production')}),
    new webpack.optimize.UglifyJsPlugin({
        sourceMap: true,
        compress: {
            warnings: false
        },
        output: {
            comments: false
        }
    }),
    // extract vendor chunks
    new webpack.optimize.CommonsChunkPlugin({name: 'vendor', filename: 'vendor.[chunkhash:8].js'}),
    new PreloadWebpackPlugin({rel: 'preload', as: 'script', include: 'all'}),
    // remove unused css
    new PurifyCSSPlugin({
        // Give paths to parse for rules. These should be absolute!
        moduleExtensions: ['.jsx', '.html', '.js'],
        paths: glob.sync(
            path.join(__dirname, 'common/*.jsx'),
            path.join(__dirname, 'common/components/**/*.jsx'),
            path.join(__dirname, 'common/containers/**/*.jsx'),
            path.join(__dirname, 'common/containers/**/*.jsx'),
            path.join(__dirname, 'node_modules/semantic-ui-react/dist/**/*.js')
        )
    }),
    // For progressive web apps
    // create manifest
    new ManifestPlugin({fileName: 'manifest.json', cache: config.manifest}),
    // AppCache + ServiceWorkers
    new OfflinePlugin({
        relativePaths: false,
        safeToUseOptionalCaches: true,
        publicPath: '/',
        caches: {
            main: [
                'vendor.*.css', 'vendor.*.js'
            ],
            additional: [':externals:'],
            optional: [':rest:']
        },
        excludes: ['.htaccess'],
        AppCache: false,
        ServiceWorker: {
            navigateFallbackURL: '/',
            events: true
        }
    })
)
// minimize webpack output
{'fraction_non_alphanumeric': 0.15174847609881295, 'fraction_numerical': 0.0009624639076034649, 'mean_word_length': 2.88715710723192, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3689130', 'n_tokens_mistral': 1820, 'n_tokens_neox': 1801, 'n_words': 393}