Skip to content

Commit

Permalink
add support for webpack4
Browse files Browse the repository at this point in the history
  • Loading branch information
andriijas committed Feb 8, 2018
1 parent 409b0fb commit 7f59497
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
52 changes: 34 additions & 18 deletions lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,14 @@ ManifestPlugin.prototype.apply = function(compiler) {
var seed = this.opts.seed || {};
var moduleAssets = {};

compiler.plugin("compilation", function (compilation) {
compilation.plugin('module-asset', function (module, file) {
moduleAssets[file] = path.join(
path.dirname(file),
path.basename(module.userRequest)
);
});
});

compiler.plugin('emit', function(compilation, compileCallback) {
var moduleAsset = function (module, file) {
moduleAssets[file] = path.join(
path.dirname(file),
path.basename(module.userRequest)
);
};

var emit = function(compilation, compileCallback) {
var publicPath = compilation.options.output.publicPath;
var stats = compilation.getStats().toJson();

Expand All @@ -61,7 +59,7 @@ ManifestPlugin.prototype.apply = function(compiler) {
path: path,
chunk: chunk,
name: name,
isInitial: chunk.isInitial ? chunk.isInitial() : chunk.initial,
isInitial: chunk.isInitial ? chunk.isInitial() : chunk.isOnlyInitial(),
isChunk: true,
isAsset: false,
isModuleAsset: false
Expand Down Expand Up @@ -172,14 +170,32 @@ ManifestPlugin.prototype.apply = function(compiler) {

// NOTE: make sure webpack is not writing multiple manifests simultaneously
lock(function(release) {
compiler.plugin('after-emit', function(compilation, cb) {
release();
cb();
});
if (compiler.hooks) {
compiler.hooks.afterEmit.tap('ManifestPlugin', function(compilation) {
release();
});
} else {
compiler.plugin('after-emit', function(compilation, cb) {
release();
cb();
});

compilation.applyPluginsAsync('webpack-manifest-plugin-after-emit', manifest, compileCallback);
}
});
}.bind(this);

compilation.applyPluginsAsync('webpack-manifest-plugin-after-emit', manifest, compileCallback);
if (compiler.hooks) {
compiler.hooks.compilation.tap('ManifestPlugin', function (compilation) {
compilation.hooks.moduleAsset.tap('ManifestPlugin', moduleAsset);
});
}.bind(this));
compiler.hooks.emit.tap('ManifestPlugin', emit);
} else {
compiler.plugin('compilation', function (compilation) {
compilation.plugin('module-asset', moduleAsset);
});
compiler.plugin('emit', emit);
}
};

module.exports = ManifestPlugin;
module.exports = ManifestPlugin;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"node": ">=4"
},
"peerDependencies": {
"webpack": "2 || 3"
"webpack": "2 || 3 || 4"
},
"devDependencies": {
"codecov": "^2.2.0",
Expand Down

0 comments on commit 7f59497

Please sign in to comment.