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'
]
}
we want to hook into the webpack chunk loader strategy and load the chunks from the build 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'