From 073b7219ffb1abfad93d923ea42d49ebd9c4dd3e Mon Sep 17 00:00:00 2001
From: Pan <panfree23@gmail.com>
Date: Thu, 23 Nov 2017 10:33:29 +0800
Subject: [PATCH] chore:refine build:prod

---
 build/utils.js             |  3 ++-
 build/webpack.prod.conf.js | 20 +++++++++++++++-----
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/build/utils.js b/build/utils.js
index e15947b1..1d2b492e 100644
--- a/build/utils.js
+++ b/build/utils.js
@@ -21,7 +21,8 @@ exports.cssLoaders = function (options) {
   }
 
   var postcssLoader = {
-    loader: 'postcss-loader'
+    loader: 'postcss-loader',
+    sourceMap: options.sourceMap
   }
 
   // generate loader string to be used with extract text plugin
diff --git a/build/webpack.prod.conf.js b/build/webpack.prod.conf.js
index c9a6c1ca..0e2b0562 100644
--- a/build/webpack.prod.conf.js
+++ b/build/webpack.prod.conf.js
@@ -82,7 +82,7 @@ var webpackConfig = merge(baseWebpackConfig, {
     // split vendor js into its own file
     new webpack.optimize.CommonsChunkPlugin({
       name: 'vendor',
-      minChunks: function (module, count) {
+      minChunks: function (module) {
         // any required modules inside node_modules are extracted to vendor
         return (
           module.resource &&
@@ -93,6 +93,12 @@ var webpackConfig = merge(baseWebpackConfig, {
         )
       }
     }),
+    // extract webpack runtime and module manifest to its own file in order to
+    // prevent vendor hash from being updated whenever app bundle is updated
+    new webpack.optimize.CommonsChunkPlugin({
+      name: 'manifest',
+      minChunks: Infinity
+    }),
     // split echarts into its own file
     new webpack.optimize.CommonsChunkPlugin({
       async: 'echarts',
@@ -109,12 +115,16 @@ var webpackConfig = merge(baseWebpackConfig, {
         return context && (context.indexOf('xlsx') >= 0);
       }
     }),
-    // extract webpack runtime and module manifest to its own file in order to
-    // prevent vendor hash from being updated whenever app bundle is updated
+    // This instance extracts shared chunks from code splitted chunks and bundles them
+    // in a separate chunk, similar to the vendor chunk
+    // see: https://webpack.js.org/plugins/commons-chunk-plugin/#extra-async-commons-chunk
     new webpack.optimize.CommonsChunkPlugin({
-      name: 'manifest',
-      chunks: ['vendor']
+      name: 'app',
+      async: 'vendor-async',
+      children: true,
+      minChunks: 3
     }),
+
     // copy custom static assets
     new CopyWebpackPlugin([{
       from: path.resolve(__dirname, '../static'),
-- 
GitLab