Skip to content

Commit 7f59497

Browse files
committed
add support for webpack4
1 parent 409b0fb commit 7f59497

File tree

2 files changed

+35
-19
lines changed

2 files changed

+35
-19
lines changed

lib/plugin.js

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,14 @@ ManifestPlugin.prototype.apply = function(compiler) {
3333
var seed = this.opts.seed || {};
3434
var moduleAssets = {};
3535

36-
compiler.plugin("compilation", function (compilation) {
37-
compilation.plugin('module-asset', function (module, file) {
38-
moduleAssets[file] = path.join(
39-
path.dirname(file),
40-
path.basename(module.userRequest)
41-
);
42-
});
43-
});
44-
45-
compiler.plugin('emit', function(compilation, compileCallback) {
36+
var moduleAsset = function (module, file) {
37+
moduleAssets[file] = path.join(
38+
path.dirname(file),
39+
path.basename(module.userRequest)
40+
);
41+
};
42+
43+
var emit = function(compilation, compileCallback) {
4644
var publicPath = compilation.options.output.publicPath;
4745
var stats = compilation.getStats().toJson();
4846

@@ -61,7 +59,7 @@ ManifestPlugin.prototype.apply = function(compiler) {
6159
path: path,
6260
chunk: chunk,
6361
name: name,
64-
isInitial: chunk.isInitial ? chunk.isInitial() : chunk.initial,
62+
isInitial: chunk.isInitial ? chunk.isInitial() : chunk.isOnlyInitial(),
6563
isChunk: true,
6664
isAsset: false,
6765
isModuleAsset: false
@@ -172,14 +170,32 @@ ManifestPlugin.prototype.apply = function(compiler) {
172170

173171
// NOTE: make sure webpack is not writing multiple manifests simultaneously
174172
lock(function(release) {
175-
compiler.plugin('after-emit', function(compilation, cb) {
176-
release();
177-
cb();
178-
});
173+
if (compiler.hooks) {
174+
compiler.hooks.afterEmit.tap('ManifestPlugin', function(compilation) {
175+
release();
176+
});
177+
} else {
178+
compiler.plugin('after-emit', function(compilation, cb) {
179+
release();
180+
cb();
181+
});
182+
183+
compilation.applyPluginsAsync('webpack-manifest-plugin-after-emit', manifest, compileCallback);
184+
}
185+
});
186+
}.bind(this);
179187

180-
compilation.applyPluginsAsync('webpack-manifest-plugin-after-emit', manifest, compileCallback);
188+
if (compiler.hooks) {
189+
compiler.hooks.compilation.tap('ManifestPlugin', function (compilation) {
190+
compilation.hooks.moduleAsset.tap('ManifestPlugin', moduleAsset);
181191
});
182-
}.bind(this));
192+
compiler.hooks.emit.tap('ManifestPlugin', emit);
193+
} else {
194+
compiler.plugin('compilation', function (compilation) {
195+
compilation.plugin('module-asset', moduleAsset);
196+
});
197+
compiler.plugin('emit', emit);
198+
}
183199
};
184200

185-
module.exports = ManifestPlugin;
201+
module.exports = ManifestPlugin;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"node": ">=4"
1313
},
1414
"peerDependencies": {
15-
"webpack": "2 || 3"
15+
"webpack": "2 || 3 || 4"
1616
},
1717
"devDependencies": {
1818
"codecov": "^2.2.0",

0 commit comments

Comments
 (0)