const path = require('path'); const merge = require('webpack-merge'); const webpack = require('webpack'); const webpackCommon = require('./../../../.webpack/webpack.common.js'); // Plugins const { CleanWebpackPlugin } = require('clean-webpack-plugin'); const CopyWebpackPlugin = require('copy-webpack-plugin'); const ExtractCssChunksPlugin = require('extract-css-chunks-webpack-plugin'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const workboxPlugin = require('workbox-webpack-plugin'); // const SRC_DIR = path.join(__dirname, '../src'); const DIST_DIR = path.join(__dirname, '../dist'); const PUBLIC_DIR = path.join(__dirname, '../public'); // Env Vars const PUBLIC_URL = process.env.PUBLIC_URL || ''; const APP_CONFIG = process.env.APP_CONFIG || 'config/default.js'; module.exports = (env, argv) => { const commonConfig = webpackCommon(env, argv, { SRC_DIR, DIST_DIR }); return merge(commonConfig, { // https://webpack.js.org/configuration/mode/#mode-production mode: 'production', stats: { colors: true, hash: true, timings: true, assets: true, chunks: false, chunkModules: false, modules: false, children: false, warnings: true, }, optimization: { minimize: true, sideEffects: true, }, output: { path: DIST_DIR, filename: '[name].bundle.[chunkhash].js', }, // TODO: // Do we need to rip anything out of the more generic common.js we're // merging with this? plugins: [ // Longer build. Let's report progress new webpack.ProgressPlugin(), // Clean output.path new CleanWebpackPlugin(), // "Public" Folder new CopyWebpackPlugin([ { from: PUBLIC_DIR, to: DIST_DIR, toType: 'dir', // Ignore our HtmlWebpackPlugin template file ignore: ['index.html', '.DS_Store'], }, ]), new ExtractCssChunksPlugin({ filename: '[name].css', chunkFilename: '[id].css', // hot: true /* only necessary if hot reloading not function*/ }), /** * This generates our index.html file from the specified template. * This is the easiest way to inject custom configuration and extensions. */ new HtmlWebpackPlugin({ template: `${PUBLIC_DIR}/index.html`, filename: 'index.html', templateParameters: { PUBLIC_URL: PUBLIC_URL, APP_CONFIG: APP_CONFIG, }, // favicon: `${PUBLIC_DIR}/favicon.ico`, }), new workboxPlugin.GenerateSW({ swDest: 'sw.js', clientsClaim: true, skipWaiting: true, }), ], }); };