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 webpack 4 #55

Merged
merged 1 commit into from
Mar 12, 2018
Merged
Changes from all commits
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
Add support for webpack 4
Will use webpack's new `.hooks` API if available, and fall back
to using the deprecated `.plugin` API otherwis.

Tested locally, but couldn't find any tests in the repo.
  • Loading branch information
simonkberg committed Mar 8, 2018
commit 22488210c61a7c3108bc7c8497391e31832fb7ff
13 changes: 11 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default class ImageminPlugin {
if (this.options.disable === true) return null

// Access the assets once they have been assembled
compiler.plugin('emit', async (compilation, callback) => {
const onEmit = async (compilation, callback) => {
// Create a throttle object which will limit the number of concurrent processes running
const throttle = createThrottle(this.options.maxConcurrency)

Expand All @@ -103,7 +103,16 @@ export default class ImageminPlugin {
// if at any point we hit a snag, pass the error on to webpack
callback(err)
}
})
}

// Check if the webpack 4 plugin API is available
if (compiler.hooks) {
// Register emit event listener for webpack 4
compiler.hooks.emit.tapAsync(this.constructor.name, onEmit)
} else {
// Register emit event listener for older webpack versions
compiler.plugin('emit', onEmit)
}
}

/**
Expand Down