This commit is contained in:
Pan 2018-07-27 14:29:55 +08:00
parent f59a39390e
commit 758330dee6
2 changed files with 18 additions and 4 deletions

View File

@ -11,11 +11,19 @@ const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin') const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin') const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin') const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const crypto = require('crypto');
function resolve(dir) { function resolve(dir) {
return path.join(__dirname, '..', 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 env = require('../config/' + process.env.env_config + '.env')
const webpackConfig = merge(baseWebpackConfig, { const webpackConfig = merge(baseWebpackConfig, {
@ -30,8 +38,8 @@ const webpackConfig = merge(baseWebpackConfig, {
devtool: config.build.productionSourceMap ? config.build.devtool : false, devtool: config.build.productionSourceMap ? config.build.devtool : false,
output: { output: {
path: config.build.assetsRoot, path: config.build.assetsRoot,
filename: utils.assetsPath('js/[name].[chunkhash].js'), filename: utils.assetsPath('js/[name].[chunkhash:8].js'),
chunkFilename: utils.assetsPath('js/[name].[chunkhash].js') chunkFilename: utils.assetsPath('js/[name].[chunkhash:8].js')
}, },
plugins: [ plugins: [
// http://vuejs.github.io/vue-loader/en/workflow/production.html // 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` //`runtime` must same as runtimeChunk name. default is `runtime`
inline: /runtime\..*\.js$/ 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 // keep module.id stable when vender modules does not change
new webpack.HashedModuleIdsPlugin(), new webpack.HashedModuleIdsPlugin(),
// copy custom static assets // copy custom static assets

View File

@ -50,8 +50,6 @@
"normalize.css": "7.0.0", "normalize.css": "7.0.0",
"nprogress": "0.2.0", "nprogress": "0.2.0",
"screenfull": "3.3.2", "screenfull": "3.3.2",
"script-ext-html-webpack-plugin": "2.0.1",
"serve-static": "1.13.2",
"showdown": "1.8.6", "showdown": "1.8.6",
"simplemde": "1.11.2", "simplemde": "1.11.2",
"sortablejs": "1.7.0", "sortablejs": "1.7.0",
@ -102,7 +100,9 @@
"rimraf": "2.6.2", "rimraf": "2.6.2",
"sass-loader": "7.0.3", "sass-loader": "7.0.3",
"script-loader": "0.7.2", "script-loader": "0.7.2",
"script-ext-html-webpack-plugin": "2.0.1",
"semver": "5.5.0", "semver": "5.5.0",
"serve-static": "1.13.2",
"shelljs": "0.8.2", "shelljs": "0.8.2",
"svg-sprite-loader": "3.8.0", "svg-sprite-loader": "3.8.0",
"uglifyjs-webpack-plugin": "1.2.7", "uglifyjs-webpack-plugin": "1.2.7",