v2.0.0
imagemin-webpack-plugin now uses the context
option from webpack to work from for all file paths, and includes it's own context
that will be joined with the webpack context for any external images.
This is a breaking change for anyone that relied on the old way of using externalImages
. It will now respect the context
option, and may break the configs for many people.
If you don't use the externalImages
option, this release should be safe to upgrade to without any changes.
Full Changelog:
- Fixed a bug where the plugin would read images from disk twice (thanks @eamodio)
- Added the
context
option toexternalImages
and have it respect the context.
For convenience, here is the major change to the externalImages
option:
options.externalImages
type: Object
default: { context: '.', sources: [], destination: null }
Include any external images (those not included in webpack's compilation assets) that you want to be parsed by imagemin.
If a destination value is not supplied the files are optimized in place. You can optionally set either of these to a function which will be invoked at the last possible second before optimization to grab files that might not exist at the time of writing the config (see #37 for more info).
The paths will work based on the webpack's (and this plugin's) context
option, so in the following example, the files will be read from ./src/images/**/*.png
and will be written to .src/public/images/**/*.png
Context only applies to the sources
array.
Example:
import ImageminPlugin from 'imagemin-webpack-plugin'
import glob from 'glob'
module.exports = {
plugins: [
new ImageminPlugin({
externalImages: {
context: 'src', // Important! This tells the plugin where to "base" the paths at
sources: glob.sync('src/images/**/*.png'),
destination: 'src/public/images'
}
})
]
}