import { join } from "path" import { HotModuleReplacementPlugin, DllReferencePlugin, } from "webpack" import WebpackNotifierPlugin from "webpack-notifier" import HtmlWebpackPlugin from "html-webpack-plugin" const defaultEnv = { production: process.env.NODE_ENV === "production", dev: !process.env.NODE_ENV || process.env.NODE_ENV === "", test: process.env.NODE_ENV === "test", } export default (env) => { env = { ...defaultEnv, ...env, } return { module: { loaders: [ // ... ], }, plugins: [ new HtmlWebpackPlugin({ template: join(__dirname, "entry", "index.html"), inject: false, ...env.dll && { externals: [ "/dependencies.dll.js" ], }, }), ...env.dev ? [ new WebpackNotifierPlugin(), new HotModuleReplacementPlugin(), ] : [], ...env.dll ? [ new DllReferencePlugin({ context: __dirname, // generated by webpack.dll.config.babel.js manifest: require("./dist/dependencies.dll.manifest.json"), // name: "./dist/dependencies.dll.js", }), ] : [], ], entry: { // ... }, output: { // publicPath has to be defined so HtmlWebpackPlugin serve correct js // in script tags // (because historyApiFallback will root things like /a/b to the // index.html, and script tag need a absolute url for the script) publicPath: "/", path: "dist", filename: "[name].[hash].js", }, devServer: { // when you serve static files during development, this is necessary // eg: dependencies.dll.js contentBase: "dist", }, } }