Skip to content

Commit 939ddc8

Browse files
authored
Added support for Web worker chunk template plugin (#353)
* Support WebWorkerChunkTemplatePlugin * changelog
1 parent 5cf45eb commit 939ddc8

4 files changed

+30
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ _Note: Gaps between patch versions are faulty, broken or test releases._
1717

1818
<!-- Add changelog entries for new changes under this section -->
1919

20+
* **New Feature**
21+
* Support [WebWorkerChunkTemplatePlugin](https://github.com/webpack/webpack/blob/c9d4ff7b054fc581c96ce0e53432d44f9dd8ca72/lib/webworker/WebWorkerChunkTemplatePlugin.js) ([#353](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/353) by [@Gongreg](https://github.com/Gongreg))
22+
2023
* **Bug Fix**
2124
* Support any custom `globalObject` option in Webpack Config. ([#352](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/352) by [@Gongreg](https://github.com/Gongreg))
2225

src/parseUtils.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ function parseBundle(bundlePath) {
7979
return;
8080
}
8181

82+
// Webpack v4 WebWorkerChunkTemplatePlugin
83+
// globalObject.chunkCallbackName([<chunks>],<modules>, ...);
84+
// Both globalObject and chunkCallbackName can be changed through the config, so we can't check them.
85+
if (isAsyncWebWorkerChunkExpression(node)) {
86+
state.locations = getModulesLocations(args[1]);
87+
return;
88+
}
89+
90+
8291
// Walking into arguments because some of plugins (e.g. `DedupePlugin`) or some Webpack
8392
// features (e.g. `umd` library output) can wrap modules list into additional IIFE.
8493
_.each(args, arg => c(arg, state));
@@ -212,6 +221,18 @@ function mayBeAsyncChunkArguments(args) {
212221
);
213222
}
214223

224+
function isAsyncWebWorkerChunkExpression(node) {
225+
const {callee, type, arguments: args} = node;
226+
227+
return (
228+
type === 'CallExpression' &&
229+
callee.type === 'MemberExpression' &&
230+
args.length === 2 &&
231+
isChunkIds(args[0]) &&
232+
isModulesList(args[1])
233+
);
234+
}
235+
215236
function getModulesLocations(node) {
216237
if (node.type === 'ObjectExpression') {
217238
// Modules hash
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
self.chunkCallbackName([27],{1:function(e,n,t){console.log("Chuck Norris")}});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"modules": {
3+
"1": "function(e,n,t){console.log(\"Chuck Norris\")}"
4+
}
5+
}

0 commit comments

Comments
 (0)