Automatically optimize (compress) all images used in Nuxt.js
@nuxtjs/imagemin
dependency to your projectyarn add --dev @nuxtjs/imagemin # or npm install --save-dev @nuxtjs/imagemin
@nuxtjs/imagemin
to the buildModules
section of nuxt.config.js
export default {
buildModules: [
// Simple usage
'@nuxtjs/imagemin',
// With options
['@nuxtjs/imagemin', { /* module options */ }]
]
}
:warning: If you are using Nuxt < v2.9 you have to install the module as a dependency
(No --dev
or --save-dev
flags) and use modules
section in nuxt.config.js
instead of buildModules
.
export default {
buildModules: [
'@nuxtjs/imagemin'
],
imagemin: {
/* module options */
}
}
See image-minimizer-webpack-plugin for the complete list of options available.
enableInDev
Boolean
false
Images will be minified in development mode, if this option is set to true
.
This could increase the build time.
minimizerOptions
Object
plugins: [
['gifsicle', { interlaced: true }],
['jpegtran', { progressive: true }],
['optipng', { optimizationLevel: 5 }],
['svgo', { plugins: [{ removeViewBox: false }] }]
]
yarn install
or npm install
npm run dev
Copyright (c) Nuxt Community