Skip to content

Commit 8763f5e

Browse files
committed
Fix: Use new webpack 4 plugin API to get rid of a deprecation warning
1 parent 3ea37d2 commit 8763f5e

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

index.js

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,32 @@ const { RawSource } = require('webpack-sources');
44
class MiniHtmlWebpackPlugin {
55
constructor(options = {}) {
66
this.options = options;
7+
this.plugin = this.plugin.bind(this);
78
}
8-
apply(compiler) {
9-
const { filename, template, context } = this.options;
109

11-
compiler.plugin('emit', (compilation, cb) => {
12-
const { publicPath } = compilation.options.output;
13-
const files = getFiles(normalizeEntrypoints(compilation.entrypoints));
10+
plugin(compilation, callback) {
11+
const { publicPath } = compilation.options.output;
12+
const { filename = 'index.html', template, context } = this.options;
1413

15-
compilation.assets[filename || 'index.html'] = new RawSource(
16-
(template || defaultTemplate)(
17-
Object.assign({}, { publicPath }, context, files)
18-
)
19-
);
14+
const files = getFiles(normalizeEntrypoints(compilation.entrypoints));
2015

21-
cb();
22-
});
16+
compilation.assets[filename] = new RawSource(
17+
(template || defaultTemplate)(
18+
Object.assign({}, { publicPath }, context, files)
19+
)
20+
);
21+
22+
callback();
23+
}
24+
25+
apply(compiler) {
26+
if (compiler.hooks) {
27+
// Webpack 4
28+
compiler.hooks.emit.tapAsync('MiniHtmlWebpackPlugin', this.plugin);
29+
} else {
30+
// Webpack 3
31+
compiler.plugin('emit', this.plugin);
32+
}
2333
}
2434
}
2535

0 commit comments

Comments
 (0)