Skip to content
This repository was archived by the owner on Jun 8, 2022. It is now read-only.

Commit 49463bc

Browse files
committed
Single variable for chunk filename
1 parent 54520ef commit 49463bc

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/chunk-manifest-webpack-plugin.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,19 @@ class ChunkManifestPlugin {
2020
apply(compiler) {
2121
const manifestFilename = this.manifestFilename;
2222
const manifestVariable = this.manifestVariable;
23-
let oldChunkFilename;
23+
let chunkFilename;
2424

25-
compiler.plugin("this-compilation", function(compilation) {
25+
compiler.plugin("this-compilation", compilation => {
2626
const mainTemplate = compilation.mainTemplate;
27-
mainTemplate.plugin("require-ensure", function(source, chunk, hash) {
28-
const filename =
29-
this.outputOptions.chunkFilename || this.outputOptions.filename;
27+
mainTemplate.plugin("require-ensure", function(
28+
source,
29+
chunk,
30+
hash
31+
/*, chunkIdVariableName */
32+
) {
33+
chunkFilename = this.outputOptions.chunkFilename;
3034

31-
if (filename) {
35+
if (chunkFilename) {
3236
const chunkManifest = [chunk].reduce(function registerChunk(
3337
manifest,
3438
c
@@ -40,9 +44,9 @@ class ChunkManifestPlugin {
4044
} else {
4145
const asyncAssets = mainTemplate.applyPluginsWaterfall(
4246
"asset-path",
43-
filename,
47+
chunkFilename,
4448
{
45-
hash: hash,
49+
hash,
4650
chunk: c
4751
}
4852
);
@@ -53,7 +57,6 @@ class ChunkManifestPlugin {
5357
},
5458
{});
5559

56-
oldChunkFilename = this.outputOptions.chunkFilename;
5760
this.outputOptions.chunkFilename = "__CHUNK_MANIFEST__";
5861
// mark as asset for emitting
5962
compilation.assets[manifestFilename] = new RawSource(
@@ -65,15 +68,16 @@ class ChunkManifestPlugin {
6568
});
6669
});
6770

68-
compiler.plugin("compilation", function(compilation) {
69-
compilation.mainTemplate.plugin("require-ensure", function(
71+
compiler.plugin("compilation", compilation => {
72+
const mainTemplate = compilation.mainTemplate;
73+
mainTemplate.plugin("require-ensure", function(
7074
source,
7175
chunk,
7276
hash,
7377
chunkIdVariableName
7478
) {
75-
if (oldChunkFilename) {
76-
this.outputOptions.chunkFilename = oldChunkFilename;
79+
if (chunkFilename) {
80+
this.outputOptions.chunkFilename = chunkFilename;
7781
}
7882

7983
const updatedSource = source.replace(

0 commit comments

Comments
 (0)