Skip to content

Commit

Permalink
Added support for Web worker chunk template plugin (#353)
Browse files Browse the repository at this point in the history
* Support WebWorkerChunkTemplatePlugin

* changelog
  • Loading branch information
Gongreg committed May 19, 2020
1 parent 5cf45eb commit 939ddc8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -17,6 +17,9 @@ _Note: Gaps between patch versions are faulty, broken or test releases._

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

* **New Feature**
* 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))

* **Bug Fix**
* 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))

Expand Down
21 changes: 21 additions & 0 deletions src/parseUtils.js
Expand Up @@ -79,6 +79,15 @@ function parseBundle(bundlePath) {
return;
}

// Webpack v4 WebWorkerChunkTemplatePlugin
// globalObject.chunkCallbackName([<chunks>],<modules>, ...);
// Both globalObject and chunkCallbackName can be changed through the config, so we can't check them.
if (isAsyncWebWorkerChunkExpression(node)) {
state.locations = getModulesLocations(args[1]);
return;
}


// Walking into arguments because some of plugins (e.g. `DedupePlugin`) or some Webpack
// features (e.g. `umd` library output) can wrap modules list into additional IIFE.
_.each(args, arg => c(arg, state));
Expand Down Expand Up @@ -212,6 +221,18 @@ function mayBeAsyncChunkArguments(args) {
);
}

function isAsyncWebWorkerChunkExpression(node) {
const {callee, type, arguments: args} = node;

return (
type === 'CallExpression' &&
callee.type === 'MemberExpression' &&
args.length === 2 &&
isChunkIds(args[0]) &&
isModulesList(args[1])
);
}

function getModulesLocations(node) {
if (node.type === 'ObjectExpression') {
// Modules hash
Expand Down
@@ -0,0 +1 @@
self.chunkCallbackName([27],{1:function(e,n,t){console.log("Chuck Norris")}});
@@ -0,0 +1,5 @@
{
"modules": {
"1": "function(e,n,t){console.log(\"Chuck Norris\")}"
}
}

0 comments on commit 939ddc8

Please sign in to comment.