Getting Started
Install the package in the project that uses Next.js.
Installation
yarn add -D next-export-optimize-images
Usage
- Write withExportImages in
next.config.js.
next.config.js
const withExportImages = require('next-export-optimize-images')
module.exports = withExportImages({
// write your next.js configuration values.
})
If you are using next-compose-plugins
next.config.js
const withPlugins = require('next-compose-plugins')
const withExportImages = require('next-export-optimize-images')
module.exports = withPlugins(
[
withExportImages,
// your other plugins here
],
{
// write your next.js configuration values.
}
)
- Change the description of the
scripts
that do thenext export
inpackage.json
package.json
{
- "export": "next build && next export",
+ "export": "next build && next export && next-export-optimize-images",
}
- Import and use next/image as usual.
<Image src="/images/img.png" width={1920} height={1280} alt="" />
// Or import as follows
<Image src={require('./img.png')} alt="" />
Local checks
- Run
yarn export
. - Run
npx http-server out