Skip to content

Commit

Permalink
Merge branch 'master' into feature/chunk-module-index
Browse files Browse the repository at this point in the history
# Conflicts:
#	test/__snapshots__/StatsTestCases.test.js.snap
  • Loading branch information
sokra committed Jun 27, 2018
2 parents 0f58776 + c384c3f commit e655de8
Show file tree
Hide file tree
Showing 8 changed files with 191 additions and 84 deletions.
31 changes: 24 additions & 7 deletions lib/web/JsonpChunkTemplatePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,23 @@

const { ConcatSource } = require("webpack-sources");

/** @typedef {import("../ChunkTemplate")} ChunkTemplate */

const getEntryInfo = chunk => {
return [chunk.entryModule].filter(Boolean).map(m =>
[m.id].concat(
Array.from(chunk.groupsIterable)[0]
.chunks.filter(c => c !== chunk)
.map(c => c.id)
)
);
};

class JsonpChunkTemplatePlugin {
/**
* @param {ChunkTemplate} chunkTemplate the chunk template
* @returns {void}
*/
apply(chunkTemplate) {
chunkTemplate.hooks.render.tap(
"JsonpChunkTemplatePlugin",
Expand All @@ -23,13 +39,7 @@ class JsonpChunkTemplatePlugin {
)}] || []).push([${JSON.stringify(chunk.ids)},`
);
source.add(modules);
const entries = [chunk.entryModule].filter(Boolean).map(m =>
[m.id].concat(
Array.from(chunk.groupsIterable)[0]
.chunks.filter(c => c !== chunk)
.map(c => c.id)
)
);
const entries = getEntryInfo(chunk);
if (entries.length > 0) {
source.add(`,${JSON.stringify(entries)}`);
} else if (prefetchChunks && prefetchChunks.length) {
Expand All @@ -49,6 +59,13 @@ class JsonpChunkTemplatePlugin {
hash.update(`${chunkTemplate.outputOptions.jsonpFunction}`);
hash.update(`${chunkTemplate.outputOptions.globalObject}`);
});
chunkTemplate.hooks.hashForChunk.tap(
"JsonpChunkTemplatePlugin",
(hash, chunk) => {
hash.update(JSON.stringify(getEntryInfo(chunk)));
hash.update(JSON.stringify(chunk.getChildIdsByOrders().prefetch) || "");
}
);
}
}
module.exports = JsonpChunkTemplatePlugin;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webpack",
"version": "4.12.1",
"version": "4.12.2",
"author": "Tobias Koppers @sokra",
"description": "Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.",
"license": "MIT",
Expand Down
192 changes: 116 additions & 76 deletions test/__snapshots__/StatsTestCases.test.js.snap

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test/statsCases/issue-7577/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("a");
1 change: 1 addition & 0 deletions test/statsCases/issue-7577/b.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "vendor";
2 changes: 2 additions & 0 deletions test/statsCases/issue-7577/c.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
console.log("c");
import(/* webpackPrefetch: true */ "./b");
1 change: 1 addition & 0 deletions test/statsCases/issue-7577/node_modules/vendor.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions test/statsCases/issue-7577/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const base = {
mode: "production",
optimization: {
runtimeChunk: true,
namedChunks: true,
splitChunks: {
minSize: 0,
chunks: "all",
cacheGroups: {
all: {
priority: -30
}
}
}
}
};
module.exports = [
Object.assign(
{
entry: "./a.js",
output: {
filename: "a-[name]-[chunkhash].js"
}
},
base
),
Object.assign(
{
entry: "./b.js",
output: {
filename: "b-[name]-[chunkhash].js"
}
},
base
),
Object.assign(
{
entry: "./c.js",
output: {
filename: "c-[name]-[chunkhash].js"
}
},
base
)
];

0 comments on commit e655de8

Please sign in to comment.