Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for webpack4 #118

Merged
merged 2 commits into from
Feb 26, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
language: node_js
node_js:
- '9'
- '8'
- '6'
- '4'

env:
- WEBPACK_VERSION=2 EXTRACT_PLUGIN_VERSION=2
- WEBPACK_VERSION=3 EXTRACT_PLUGIN_VERSION=3.0.0-rc.1
- WEBPACK_VERSION=3 EXTRACT_PLUGIN_VERSION=3.0.2
- WEBPACK_VERSION=4 EXTRACT_PLUGIN_VERSION=3.0.2

install:
- npm install
Expand Down
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(),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isInitial is only in v3.
So, I think l62 will throw error in v1/v2. and it should be like this.

isInitial: chunk. isOnlyInitial ? chunk. isOnlyInitial() : (chunk.isInitial ? chunk.isInitial() : chunk.initial),

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;
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
"node": ">=4"
},
"peerDependencies": {
"webpack": "2 || 3"
"webpack": "2 || 3 || 4"
},
"devDependencies": {
"codecov": "^2.2.0",
"css-loader": "^0.9.1",
"extract-text-webpack-plugin": "^3.0.0",
"extract-text-webpack-plugin": "^3.0.2",
"file-loader": "^0.9.0",
"jasmine": "^2.2.1",
"memory-fs": "^0.2.0",
Expand Down