Reputation: 14159
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):
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
. 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.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:
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'
Upvotes: 3
Views: 707
Reputation: 14159
As per Aug 2019, this is currently not possible with 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_get_script_filename__ = (asset: string) => string
https://github.com/webpack/webpack/pull/8462
Upvotes: 1