Skip to content

Commit 5c84368

Browse files
snitin315alexander-akait
authored andcommitted
refactor: remove webpack v4 code (#4967)
1 parent b597ae6 commit 5c84368

File tree

1 file changed

+24
-45
lines changed

1 file changed

+24
-45
lines changed

test/helpers/html-generator-plugin.js

Lines changed: 24 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -47,57 +47,36 @@ module.exports = class HTMLGeneratorPlugin {
4747
const pluginName = "html-generator-plugin";
4848

4949
compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {
50-
if (compiler.webpack) {
51-
const { RawSource } = compiler.webpack.sources;
50+
const { RawSource } = compiler.webpack.sources;
5251

53-
compilation.hooks.processAssets.tap(
54-
{
55-
name: pluginName,
56-
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
57-
},
58-
() => {
59-
const indexSource = new RawSource(HTMLContentForIndex);
60-
const testSource = new RawSource(HTMLContentForTest);
61-
const assets = compilation.getAssets();
52+
compilation.hooks.processAssets.tap(
53+
{
54+
name: pluginName,
55+
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
56+
},
57+
() => {
58+
const indexSource = new RawSource(HTMLContentForIndex);
59+
const testSource = new RawSource(HTMLContentForTest);
60+
const assets = compilation.getAssets();
6261

63-
compilation.emitAsset("index.html", indexSource);
64-
compilation.emitAsset("test.html", testSource);
62+
compilation.emitAsset("index.html", indexSource);
63+
compilation.emitAsset("test.html", testSource);
6564

66-
for (const asset of assets) {
67-
const assetName = asset.name;
65+
for (const asset of assets) {
66+
const assetName = asset.name;
6867

69-
if (assetName !== "main.js") {
70-
const assetSource = new RawSource(
71-
HTMLContentForAssets(assetName)
72-
);
73-
compilation.emitAsset(
74-
assetName.replace(".js", ".html"),
75-
assetSource
76-
);
77-
}
68+
if (assetName !== "main.js") {
69+
const assetSource = new RawSource(
70+
HTMLContentForAssets(assetName)
71+
);
72+
compilation.emitAsset(
73+
assetName.replace(".js", ".html"),
74+
assetSource
75+
);
7876
}
7977
}
80-
);
81-
} else {
82-
compilation.hooks.additionalAssets.tap(pluginName, () => {
83-
compilation.emitAsset("index.html", {
84-
source() {
85-
return HTMLContentForIndex;
86-
},
87-
size() {
88-
return HTMLContentForIndex.length;
89-
},
90-
});
91-
compilation.emitAsset("test.html", {
92-
source() {
93-
return HTMLContentForTest;
94-
},
95-
size() {
96-
return HTMLContentForTest.length;
97-
},
98-
});
99-
});
100-
}
78+
}
79+
);
10180
});
10281
}
10382
};

0 commit comments

Comments
 (0)