javascript - webpackJsonp 改变 chunkHash
问题描述
vendors: {
minSize: 20000,
test: /[\\/]node_modules[\\/]/,
chunks: 'initial',
name(module) {
// get the name. E.g. node_modules/packageName/not/this/part.js
// or node_modules/packageName
const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
// npm package names are URL-safe, but some servers don't like @ symbols
return `npm.${packageName.replace('@', '')}`;
},
reuseExistingChunk: true
}
在上面的 cacheGroup 中,我试图拆分每个 node_module,输出文件名为c[chunkhash].js
我希望 2 个不同的页面具有共同的导入,例如axios
应该具有相同的“chunkHash”,但令我惊讶的是,事实并非如此。
在查看了这些块之后,我发现这 2 个块具有相同的主体,只是它们的 webpackJsonp 不同。
块1
(window.webpackJsonp = window.webpackJsonp || []).push([[1], {
4: function (e, t, r) {
"use strict";
(function (e) {
r.d(t, "a", (function () {
return ye
}));
var n, o, i, a, c = r(0), u = r.n(c), s = r(5), l = r.n(s), f = r(6), p = r.n(f), d = r(1), h = r.n(d),
y = r(7), T = r.n(y), b = "bodyAttributes", m = "htmlAttributes", g = "titleAttributes", v = {
BASE: "base",
BODY: "body",
HEAD: "head",
HTML: "html",
...
块 2
(window.webpackJsonp = window.webpackJsonp || []).push([[2], {
5: function (e, t, r) {
"use strict";
(function (e) {
r.d(t, "a", (function () {
return ye
}));
var n, o, i, a, c = r(0), u = r.n(c), s = r(6), l = r.n(s), f = r(7), p = r.n(f), d = r(1), h = r.n(d),
y = r(8), T = r.n(y), b = "bodyAttributes", m = "htmlAttributes", g = "titleAttributes", v = {
BASE: "base",
BODY: "body",
HEAD: "head",
HTML: "html",
...
两个块具有相同的主体,但 Jsonp 索引不同。在 chunk14
中,在 chunk2 中5
这会导致浏览器两次下载相同的内容。
有逛街吗?
解决方案
我发现,这是多编译器和多入口webpack 配置之间的主要区别。
当您为 webpack 进行多编译器配置时,您将失去重用块和更好地进行代码拆分的能力。
因此,尝试坚持多入口 webpack 配置和单一运行时
推荐阅读
- angular - 如何能够对我的 dataTable 应用过滤器,该过滤器也可以在对象内部查找以过滤数据
- visual-studio - VSTS 工作项查询,包括未分配的工作项和分配给我的工作项
- php - 正确支付后如何单独插入购物车的商品?
- excel - 查找方法仅在用户窗体上工作一次
- mongodb - MongoDB 查询 - 将函数传递给 Model.find()
- kotlin - Kotlin - 来自 KType 的 KClass<*>
- azure - 使用 Azure Log Analytics 搜索存储帐户
- javascript - 没有固定高度的页脚位置
- image - 带有 Flutter 的图片库
- android - Firebase 身份验证的防火墙配置 (Android)