mirror of
https://github.com/PanJiaChen/vue-element-admin.git
synced 2025-09-10 12:50:38 +08:00
refine NamedChunksPlugin
This commit is contained in:
parent
8fecdf22d5
commit
1889cdec6e
@ -11,21 +11,17 @@ 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')
|
||||||
|
|
||||||
|
// For NamedChunksPlugin
|
||||||
|
const seen = new Set();
|
||||||
|
const nameLength = 4;
|
||||||
|
|
||||||
const webpackConfig = merge(baseWebpackConfig, {
|
const webpackConfig = merge(baseWebpackConfig, {
|
||||||
mode: 'production',
|
mode: 'production',
|
||||||
module: {
|
module: {
|
||||||
@ -76,11 +72,22 @@ 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$/
|
||||||
}),
|
}),
|
||||||
|
// keep chunk.id stable when chunk has no name
|
||||||
new webpack.NamedChunksPlugin(chunk => {
|
new webpack.NamedChunksPlugin(chunk => {
|
||||||
if (chunk.name) {
|
if (chunk.name) {
|
||||||
return chunk.name
|
return chunk.name;
|
||||||
|
}
|
||||||
|
const modules = Array.from(chunk.modulesIterable);
|
||||||
|
if (modules.length > 1) {
|
||||||
|
const hash = require("hash-sum");
|
||||||
|
const joinedHash = hash(modules.map(m => m.id).join("_"));
|
||||||
|
let len = nameLength;
|
||||||
|
while (seen.has(joinedHash.substr(0, len))) len++;
|
||||||
|
seen.add(joinedHash.substr(0, len));
|
||||||
|
return `chunk-${joinedHash.substr(0, len)}`;
|
||||||
|
} else {
|
||||||
|
return modules[0].id;
|
||||||
}
|
}
|
||||||
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(),
|
||||||
|
@ -85,6 +85,7 @@
|
|||||||
"eslint-plugin-html": "4.0.5",
|
"eslint-plugin-html": "4.0.5",
|
||||||
"file-loader": "1.1.11",
|
"file-loader": "1.1.11",
|
||||||
"friendly-errors-webpack-plugin": "1.7.0",
|
"friendly-errors-webpack-plugin": "1.7.0",
|
||||||
|
"hash-sum": "^1.0.2",
|
||||||
"html-webpack-plugin": "^4.0.0-alpha",
|
"html-webpack-plugin": "^4.0.0-alpha",
|
||||||
"husky": "0.14.3",
|
"husky": "0.14.3",
|
||||||
"lint-staged": "7.2.0",
|
"lint-staged": "7.2.0",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user