Skip to content

Commit 9faeaf4

Browse files
authored
Merge pull request #14 from duncanbeevers/webpack-5-compat-12
feat: webpack 5 compat
2 parents e8f2212 + 0e5e475 commit 9faeaf4

4 files changed

Lines changed: 843 additions & 1961 deletions

File tree

index.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
22
const { inlineSource } = require('inline-source');
33
const { getTagRegExp } = require('inline-source/lib/utils');
44
const htmlparser = require('htmlparser2');
5+
const { Compilation } = require('webpack');
56

67
class InlineSourceWebpackPlugin {
78
constructor(options = {}) {
@@ -69,7 +70,7 @@ class InlineSourceWebpackPlugin {
6970
compilation.fileDependencies.add(source.filepath);
7071
} else {
7172
// Before Webpack 4
72-
// fileDepenencies was an array
73+
// fileDependencies was an array
7374
compilation.fileDependencies.push(source.filepath);
7475
}
7576
}
@@ -124,7 +125,13 @@ class InlineSourceWebpackPlugin {
124125
*/
125126
_deleteAsset(compilation) {
126127
if (this.deleteAssets.length) {
127-
this.deleteAssets.forEach(asset => delete compilation.assets[asset.name]);
128+
if ('deleteAsset' in compilation) {
129+
this.deleteAssets.forEach(asset => {
130+
compilation.deleteAsset(asset.name);
131+
});
132+
} else {
133+
this.deleteAssets.forEach(asset => delete compilation.assets[asset.name]);
134+
}
128135
}
129136
this.deleteAssets = [];
130137
}
@@ -157,10 +164,19 @@ class InlineSourceWebpackPlugin {
157164
}
158165
});
159166
}
160-
compiler.hooks.emit.tapAsync(name, (compilation, callback) => {
161-
this._deleteAsset(compilation);
162-
callback && callback();
163-
});
167+
if (Compilation && Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE) {
168+
compiler.hooks.thisCompilation.tap(name, compilation => {
169+
compilation.hooks.processAssets.tap(
170+
{ name, stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE },
171+
() => { this._deleteAsset(compilation); }
172+
);
173+
});
174+
} else {
175+
compiler.hooks.emit.tapAsync(name, (compilation, callback) => {
176+
this._deleteAsset(compilation);
177+
callback && callback();
178+
});
179+
}
164180
} else {
165181
// webpack 2 or 3
166182
compiler.plugin('compilation', compilation => {

0 commit comments

Comments
 (0)