diff --git a/package.json b/package.json index 85f00c4..32a478a 100644 --- a/package.json +++ b/package.json @@ -12,9 +12,9 @@ "src" ], "scripts": { - "build": "webpack --env.env=prod", + "build": "webpack --env.mode=prod", "lint": "eslint statik/**/*.js", - "start": "webpack-dev-server --env.env=dev" + "start": "webpack-dev-server --env.mode=dev" }, "repository": { "type": "git", diff --git a/webpack.config.js b/webpack.config.js index 50ea949..20a6a9b 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,5 +1,5 @@ module.exports = (env) => { - const config = require(`./webpack.${env.env}`); + const config = require(`./webpack/webpack.${env.mode}`); return config; }; diff --git a/webpack.common.js b/webpack/webpack.common.js similarity index 89% rename from webpack.common.js rename to webpack/webpack.common.js index 80a3a59..1bcc16b 100644 --- a/webpack.common.js +++ b/webpack/webpack.common.js @@ -8,7 +8,7 @@ module.exports = { vendor: './statik/scripts/vendor.js' }, output: { - filename: '[name].bundle.js', + filename: '[name].[chunkhash].bundle.js', path: path.resolve('dist') }, module: { @@ -39,7 +39,7 @@ module.exports = { ] }, plugins: [ - new CleanWebpackPlugin(['dist']), + new CleanWebpackPlugin(['dist'], { root: path.resolve() }), new HtmlWebpackPlugin({ template: './statik/index.html' }) diff --git a/webpack.dev.js b/webpack/webpack.dev.js similarity index 90% rename from webpack.dev.js rename to webpack/webpack.dev.js index 8e4220a..3d7fb18 100644 --- a/webpack.dev.js +++ b/webpack/webpack.dev.js @@ -18,7 +18,7 @@ module.exports = merge(common, { }, { test: /\.(gif|jpg|png|svg|ico)$/, - include: path.resolve(__dirname, 'statik/images'), + include: path.resolve('statik', 'images'), use: ['file-loader'] } ] diff --git a/webpack.prod.js b/webpack/webpack.prod.js similarity index 86% rename from webpack.prod.js rename to webpack/webpack.prod.js index dd12418..6335696 100644 --- a/webpack.prod.js +++ b/webpack/webpack.prod.js @@ -40,7 +40,7 @@ module.exports = merge(common, { }, { test: /\.(gif|jpg|png|svg|ico)$/, - include: path.resolve(__dirname, 'statik/images'), + include: path.resolve('statik', 'images'), use: [ { loader: 'file-loader', @@ -55,9 +55,17 @@ module.exports = merge(common, { ] }, optimization: { + runtimeChunk: 'single', splitChunks: { chunks: 'all', - name: true + name: true, + cacheGroups: { + vendor: { + test: /[\\/]node_modules[\\/]/, + name: 'vendors', + chunks: 'all' + } + } }, minimizer: [ new OptimizeCSSAssetsPlugin({ @@ -73,6 +81,7 @@ module.exports = merge(common, { new UglifyJsWebpackPlugin({ sourceMap: true }), + new webpack.HashedModuleIdsPlugin(), new webpack.DefinePlugin({ 'process.env.NODE_ENV': JSON.stringify('production') })