[英]webpack publicPath - Use different urls to reuse bundles
Given the following scenario. 鉴于以下情况。
A webpack build producing 3 bundles, and a CI publishing them to a CDN like this (every build id produces a new folder): 一个webpack构建会生成3个bundle,CI会像这样将它们发布到CDN(每个build id都会生成一个新文件夹):
www.cdn.com/1/application.js
www.cdn.com/1/chunk-a.js
www.cdn.com/1/chunk-b.js
now, consider that the next build produces: 现在,考虑下一个构建产生:
www.cdn.com/2/application.js
www.cdn.com/2/chunk-a.js
www.cdn.com/2/chunk-b.js
It might happen that some of these files are identical, let's say that nothing changes but application.js
. 这些文件中的一些可能会完全相同,例如,除了application.js
,什么都没有改变。 We have a script that produces a manifest , it simply compares these two builds and produces: 我们有一个产生清单的脚本,它只比较这两个构建并产生:
{
files: [
'www.cdn.com/1/chunk-a.js',
'www.cdn.com/1/chunk-b.js',
'www.cdn.com/2/application.js'
]
}
1
, since there is no reason to invalidate any client cache. 我们想要加入webpack块加载器策略并从build 1
加载块,因为没有理由使任何客户端缓存无效。 To be more specific, we want to patch the release, so that we can reuse static assets if possible. 更具体地说,我们希望修补该发行版,以便在可能的情况下可以重用静态资产。
we want a hook that retrieves the request and returns a url that webpack will then use to load the asset, something like: 我们需要一个钩子来检索请求并返回一个URL,然后webpack将使用该URL来加载资产,例如:
interface Hook {
(chunk: string): string
}
hook('chunk-a') => 'www.cdn.com/1/chunk-a.js'
hook('chunk-b') => 'www.cdn.com/1/chunk-b.js'
hook('application.js') => 'www.cdn.com/2/application.js'
As per Aug 2019, this is currently not possible with webpack@4 . 从2019年8月开始, 当前无法通过webpack @ 4实现此功能 。 A pull request has been merged into webpack@next
and will deliver a feature exposing how url is generated in webpack@5. 一个拉取请求已合并到webpack@next
,并将提供一个功能来揭示如何在webpack @ 5中生成url。
__webpack_get_script_filename__ = (asset: string) => string
https://github.com/webpack/webpack/pull/8462 https://github.com/webpack/webpack/pull/8462
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.