diff --git a/package.json b/package.json index ec4ccfd..53a95e4 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,9 @@ "lodash": "^4.17.5", "webpack-sources": "^1.1.0" }, + "peerDependencies": { + "webpack": "^3.0.0 || ^4.4.0 || ^5.0.0" + }, "main": "src/index.js", "homepage": "http://github.com/NMFR/last-call-webpack-plugin", "repository": { diff --git a/src/index.js b/src/index.js index 252f5e3..f2f77c9 100644 --- a/src/index.js +++ b/src/index.js @@ -7,7 +7,9 @@ const isRegExp = require('lodash/isRegExp'); const keys = require('lodash/keys'); const values = require('lodash/values'); const webpackSources = require('webpack-sources'); +const webpackVersion = require('webpack').version; +const isWebpackGreaterThan5 = webpackVersion[0] >= 5; const PHASES = { OPTIMIZE_CHUNK_ASSETS: 'compilation.optimize-chunk-assets', OPTIMIZE_ASSETS: 'compilation.optimize-assets', @@ -62,7 +64,13 @@ class LastCallWebpackPlugin { } buildPluginDescriptor() { - return { name: 'LastCallWebpackPlugin' }; + const pluginDescriptor = { name: 'LastCallWebpackPlugin' }; + + if (isWebpackGreaterThan5) { + pluginDescriptor.stage = compilation.PROCESS_ASSETS_STAGE_OPTIMIZE + } + + return pluginDescriptor; } resetInternalState() { @@ -172,7 +180,7 @@ class LastCallWebpackPlugin { (compilation, params) => { this.resetInternalState(); - if (hasOptimizeChunkAssetsProcessors) { + if (hasOptimizeChunkAssetsProcessors && !isWebpackGreaterThan5) { compilation.hooks.optimizeChunkAssets.tapPromise( this.pluginDescriptor, chunks => this.process(compilation, PHASES.OPTIMIZE_CHUNK_ASSETS, { chunks: chunks })