Skip to content

Commit

Permalink
Merge pull request #7581 from TimHambourger/master
Browse files Browse the repository at this point in the history
Implement all path variables for webworker dynamic imports
  • Loading branch information
sokra committed Jun 23, 2018
2 parents 6dd4d76 + 1ef1241 commit 3fb49de
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 1 deletion.
19 changes: 18 additions & 1 deletion lib/webworker/WebWorkerMainTemplatePlugin.js
Expand Up @@ -54,6 +54,20 @@ class WebWorkerMainTemplatePlugin {
)} + "`,
chunk: {
id: '" + chunkId + "',
hash: `" + ${JSON.stringify(chunkMaps.hash)}[chunkId] + "`,
hashWithLength(length) {
const shortChunkHashMap = Object.create(null);
for (const chunkId of Object.keys(chunkMaps.hash)) {
if (typeof chunkMaps.hash[chunkId] === "string") {
shortChunkHashMap[chunkId] = chunkMaps.hash[
chunkId
].substr(0, length);
}
}
return `" + ${JSON.stringify(
shortChunkHashMap
)}[chunkId] + "`;
},
contentHash: {
javascript: `" + ${JSON.stringify(
chunkMaps.contentHash.javascript
Expand All @@ -74,7 +88,10 @@ class WebWorkerMainTemplatePlugin {
shortContentHashMap
)}[chunkId] + "`;
}
}
},
name: `" + (${JSON.stringify(
chunkMaps.name
)}[chunkId]||chunkId) + "`
},
contentHashType: "javascript"
}) +
Expand Down
3 changes: 3 additions & 0 deletions test/configCases/issues/issue-7563/index.js
@@ -0,0 +1,3 @@
it("should compile without error", function() {
return import(/* webpackChunkName: "one" */ "./one");
});
1 change: 1 addition & 0 deletions test/configCases/issues/issue-7563/one.js
@@ -0,0 +1 @@
module.exports = 1;
22 changes: 22 additions & 0 deletions test/configCases/issues/issue-7563/test.config.js
@@ -0,0 +1,22 @@
var fs = require('fs');

module.exports = {
noTests: true,
findBundle: function(i, options) {
var regex = new RegExp("^bundle\." + options.name, "i");
var files = fs.readdirSync(options.output.path);
var bundle = files.find(function (file) {
return regex.test(file);
});

if (!bundle) {
throw new Error(
`No file found with correct name (regex: ${
regex.source
}, files: ${files.join(", ")})`
);
}

return "./" + bundle;
}
};
65 changes: 65 additions & 0 deletions test/configCases/issues/issue-7563/webpack.config.js
@@ -0,0 +1,65 @@
"use strict";

// Have to test [hash] and [chunkhash] separately to avoid
// "Cannot use [chunkhash] or [contenthash] for chunk in 'bundle1.[hash].[hash:16].[chunkhash].[chunkhash:16].[name].[id].[query].js' (use [hash] instead)"
var testAllButHash = "[chunkhash].[chunkhash:16].[name].[id].[query]";
var testHash = "[hash].[hash:16]";

module.exports = [
{
name: "webworker-all",
target: "webworker",
output: {
filename: "bundle.webworker-all." + testAllButHash + ".js"
}
},
{
name: "webworker-hash",
target: "webworker",
output: {
filename: "bundle.webworker-hash." + testHash + ".js"
}
},
{
name: "node-all",
target: "node",
output: {
filename: "bundle.node-all." + testAllButHash + ".js"
}
},
{
name: "node",
target: "node",
output: {
filename: "bundle.node-hash." + testHash + ".js"
}
},
{
name: "async-node-all",
target: "async-node",
output: {
filename: "bundle.async-node-all." + testAllButHash + ".js"
}
},
{
name: "async-node-hash",
target: "async-node",
output: {
filename: "bundle.async-node-hash." + testHash + ".js"
}
},
{
name: "web-all",
target: "web",
output: {
filename: "bundle.web-all." + testAllButHash + ".js"
}
},
{
name: "web-hash",
target: "web",
output: {
filename: "bundle.web-hash." + testHash + ".js"
}
}
];

0 comments on commit 3fb49de

Please sign in to comment.