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

Commit 4e8c442

Browse files
committed
Drop asset on emit event
1 parent 38b3ec1 commit 4e8c442

File tree

2 files changed

+16
-23
lines changed

2 files changed

+16
-23
lines changed

src/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ class InlineChunkManifestHtmlWebpackPlugin {
4040
const chunkManifestVariable = this.chunkManifestVariable;
4141
const dropAsset = this.dropAsset;
4242

43+
compiler.plugin("emit", (compilation, callback) => {
44+
if (dropAsset) {
45+
delete compilation.assets[manifestFilename];
46+
}
47+
48+
callback();
49+
});
50+
4351
compiler.plugin("compilation", compilation => {
4452
compilation.plugin(
4553
"html-webpack-plugin-alter-asset-tags",
@@ -57,10 +65,6 @@ class InlineChunkManifestHtmlWebpackPlugin {
5765
};
5866

5967
htmlPluginData.head.unshift(newTag);
60-
61-
if (dropAsset) {
62-
delete compilation.assets[manifestFilename];
63-
}
6468
}
6569

6670
callback(null, htmlPluginData);

test/plugin-drop-asset-test.js

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,22 @@ test.cb("keep asset", t => {
2020
});
2121

2222
function isDropped(dropAsset, callback) {
23-
const assets = {};
24-
assets[manifestFilename] = {
23+
const compilation = {
24+
assets: {}
25+
};
26+
compilation.assets[manifestFilename] = {
2527
source: () => manifestFileContent
2628
};
2729

28-
const compilationPluginEvent = (compilationEvent, alterAssets) => {
29-
if (compilationEvent === "html-webpack-plugin-alter-asset-tags") {
30-
const htmlPluginData = {
31-
head: []
32-
};
33-
34-
alterAssets(htmlPluginData, (_, result) => {
35-
const asset = assets[manifestFilename];
30+
const pluginEvent = (event, emit) => {
31+
if (event === "emit") {
32+
emit(compilation, () => {
33+
const asset = compilation.assets[manifestFilename];
3634
callback(asset);
3735
});
3836
}
3937
};
4038

41-
const pluginEvent = (compilerEvent, compile) => {
42-
const compilation = {
43-
plugin: compilationPluginEvent,
44-
assets: assets
45-
};
46-
47-
compile(compilation);
48-
};
49-
5039
const fakeCompiler = { plugin: pluginEvent };
5140

5241
const plugin = new InlineChunkManifestHtmlWebpackPlugin({

0 commit comments

Comments
 (0)