From 758330dee6abc1a39fef04d955126703e85ebf23 Mon Sep 17 00:00:00 2001 From: Pan Date: Fri, 27 Jul 2018 14:29:55 +0800 Subject: [PATCH] refine --- build/webpack.prod.conf.js | 18 ++++++++++++++++-- package.json | 4 ++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/build/webpack.prod.conf.js b/build/webpack.prod.conf.js index 158bb77f..c76ee29b 100644 --- a/build/webpack.prod.conf.js +++ b/build/webpack.prod.conf.js @@ -11,11 +11,19 @@ const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin') const MiniCssExtractPlugin = require('mini-css-extract-plugin') const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin') const UglifyJsPlugin = require('uglifyjs-webpack-plugin') +const crypto = require('crypto'); + function resolve(dir) { return path.join(__dirname, '..', dir) } +function createHash(data) { + const length = 8 + const hash = crypto.createHash('md5').update(data).digest("hex") + return hash.slice(0, length) +} + const env = require('../config/' + process.env.env_config + '.env') const webpackConfig = merge(baseWebpackConfig, { @@ -30,8 +38,8 @@ const webpackConfig = merge(baseWebpackConfig, { devtool: config.build.productionSourceMap ? config.build.devtool : false, output: { path: config.build.assetsRoot, - filename: utils.assetsPath('js/[name].[chunkhash].js'), - chunkFilename: utils.assetsPath('js/[name].[chunkhash].js') + filename: utils.assetsPath('js/[name].[chunkhash:8].js'), + chunkFilename: utils.assetsPath('js/[name].[chunkhash:8].js') }, plugins: [ // http://vuejs.github.io/vue-loader/en/workflow/production.html @@ -69,6 +77,12 @@ const webpackConfig = merge(baseWebpackConfig, { //`runtime` must same as runtimeChunk name. default is `runtime` inline: /runtime\..*\.js$/ }), + new webpack.NamedChunksPlugin(chunk => { + if (chunk.name) { + return chunk.name + } + return createHash(Array.from(chunk.modulesIterable, m => m.id).join('_')) + }), // keep module.id stable when vender modules does not change new webpack.HashedModuleIdsPlugin(), // copy custom static assets diff --git a/package.json b/package.json index 1fe66cab..3fb766e7 100644 --- a/package.json +++ b/package.json @@ -50,8 +50,6 @@ "normalize.css": "7.0.0", "nprogress": "0.2.0", "screenfull": "3.3.2", - "script-ext-html-webpack-plugin": "2.0.1", - "serve-static": "1.13.2", "showdown": "1.8.6", "simplemde": "1.11.2", "sortablejs": "1.7.0", @@ -102,7 +100,9 @@ "rimraf": "2.6.2", "sass-loader": "7.0.3", "script-loader": "0.7.2", + "script-ext-html-webpack-plugin": "2.0.1", "semver": "5.5.0", + "serve-static": "1.13.2", "shelljs": "0.8.2", "svg-sprite-loader": "3.8.0", "uglifyjs-webpack-plugin": "1.2.7",