diff --git a/.travis.yml b/.travis.yml index be0c1e8..6883c97 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/lib/plugin.js b/lib/plugin.js index 9ef9d8f..1b6976f 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -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(); @@ -57,11 +55,14 @@ ManifestPlugin.prototype.apply = function(compiler) { name = path; } + // Webpack 4: .isOnlyInitial() + // Webpack 3: .isInitial() + // Webpack 1/2: .initial return files.concat({ path: path, chunk: chunk, name: name, - isInitial: chunk.isInitial ? chunk.isInitial() : chunk.initial, + isInitial: chunk.isOnlyInitial ? chunk.isOnlyInitial() : (chunk.isInitial ? chunk.isInitial() : chunk.initial), isChunk: true, isAsset: false, isModuleAsset: false @@ -172,14 +173,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; \ No newline at end of file diff --git a/package.json b/package.json index 7b73d54..94efbe9 100644 --- a/package.json +++ b/package.json @@ -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",