Automatically optimize (compress) all images used in Nuxt.js
- Add
@nuxtjs/imagemindependency to your project
yarn add --dev @nuxtjs/imagemin # or npm install --save-dev @nuxtjs/imagemin- Add
@nuxtjs/imageminto thebuildModulessection ofnuxt.config.js
export default {
buildModules: [
// Simple usage
'@nuxtjs/imagemin',
// With options
['@nuxtjs/imagemin', { /* module options */ }]
]
}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.
- Type:
Boolean - Default:
false
Images will be minified in development mode, if this option is set to true.
This could increase the build time.
- Type:
Object - Default:
plugins: [
['gifsicle', { interlaced: true }],
['jpegtran', { progressive: true }],
['optipng', { optimizationLevel: 5 }],
['svgo', { plugins: [{ removeViewBox: false }] }]
]- Clone this repository
- Install dependencies using
yarn installornpm install - Start development server using
npm run dev
Copyright (c) Nuxt Community