From c448d8d52a1e790ec8939f9901ea5b52b80af8ef Mon Sep 17 00:00:00 2001 From: Pan Date: Fri, 27 Jul 2018 16:48:56 +0800 Subject: [PATCH] refine --- build/webpack.prod.conf.js | 28 ++++++++++++++++++++-------- config/index.js | 5 +++-- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/build/webpack.prod.conf.js b/build/webpack.prod.conf.js index f60196d..adceb7b 100644 --- a/build/webpack.prod.conf.js +++ b/build/webpack.prod.conf.js @@ -48,7 +48,8 @@ const webpackConfig = merge(baseWebpackConfig, { }), // extract css into its own file new MiniCssExtractPlugin({ - filename: utils.assetsPath('css/[name].[chunkhash].css'), + filename: utils.assetsPath('css/[name].[contenthash:8].css'), + chunkFilename: utils.assetsPath('css/[name].[contenthash:8].css'), }), // Compress extracted CSS. We are using this plugin so that possible // duplicated CSS from different components can be deduped. @@ -81,7 +82,7 @@ const webpackConfig = merge(baseWebpackConfig, { // https://github.com/kangax/html-minifier#options-quick-reference }, // necessary to consistently work with multiple chunks - chunksSortMode: 'dependency' + chunksSortMode: 'none' }), // keep module.id stable when vender modules does not change new webpack.HashedModuleIdsPlugin(), @@ -92,11 +93,8 @@ const webpackConfig = merge(baseWebpackConfig, { ignore: ['.*'] }]) ], + // recordsPath: path.join(__dirname, 'records.json'), optimization: { - splitChunks: { - chunks: 'all', - name: 'vendors', - }, runtimeChunk: 'single', minimizer: [ new UglifyJsPlugin({ @@ -130,9 +128,23 @@ if (config.build.productionGzip) { ) } -if (config.build.bundleAnalyzerReport) { +if (config.build.generateAnalyzerReport || config.build.bundleAnalyzerReport) { const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin - webpackConfig.plugins.push(new BundleAnalyzerPlugin()) + + if (config.build.bundleAnalyzerReport) { + webpackConfig.plugins.push(new BundleAnalyzerPlugin({ + analyzerPort: 8080, + generateStatsFile: false + })) + } + + if (config.build.generateAnalyzerReport) { + webpackConfig.plugins.push(new BundleAnalyzerPlugin({ + analyzerMode: 'static', + openAnalyzer: false + })) + } } module.exports = webpackConfig + diff --git a/config/index.js b/config/index.js index 9bf376a..10150b7 100644 --- a/config/index.js +++ b/config/index.js @@ -71,7 +71,7 @@ module.exports = { productionSourceMap: false, // https://webpack.js.org/configuration/devtool/#production - devtool: '#source-map', + devtool: '#ource-map', // Gzip off by default as many popular static hosts such as // Surge or Netlify already gzip all static assets for you. @@ -84,6 +84,7 @@ module.exports = { // View the bundle analyzer report after build finishes: // `npm run build --report` // Set to `true` or `false` to always turn it on or off - bundleAnalyzerReport: process.env.npm_config_report + bundleAnalyzerReport: process.env.npm_config_report || false, + generateAnalyzerReport: process.env.npm_config_generate_report || false } }