---
title: "Discussion on \"Image optimization for static NextJS sites\" | Hashnode"
description: "Discussion on \"Image optimization for static NextJS sites\". NextJS is a great tool for building React apps. It comes with a lot of flexibility and awesome features like  static site generation  (with next export) and  image optimization  (with the next/image component). \nBut there is a problem.\nCurrently, it ..."
url: "https://hashnode.com/posts/image-optimization-for-static-nextjs-sites/604cae1e37d84907f1327f94"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Image optimization for static NextJS sites](https://whereisthemouse.hashnode.dev/image-optimization-for-static-nextjs-sites?utm_source=hashnode&utm_medium=feed)

NextJS is a great tool for building React apps. It comes with a lot of flexibility and awesome features like static site generation (with next export) and image optimization (with the next/image component). But there is a problem. Currently, it ...

Mar 13, 2021 · 3 min read · whereisthemouse.hashnode.dev  
Updated Jul 14, 2022  
Read the article

-   [#nextjs](https://hashnode.com/tag/nextjs)
-   [#reactjs](https://hashnode.com/tag/reactjs)
-   [#images](https://hashnode.com/tag/images)

## Written by

[Iva Kop](https://hashnode.com/@IvaKop)

@IvaKop

  
[View profile](https://hashnode.com/@IvaKop)

Software developer | Content creator | ReactJS enthusiast

## Responses 3

Markdown supported · ⌘↵ to post

[Oscar Cárcamo Zumelzu](https://hashnode.com/@oscars810)

[Sep 27, 2021](https://hashnode.com/posts/image-optimization-for-static-nextjs-sites/604cae1e37d84907f1327f94/comment/61521a97040ee87236950749)

Hi! I'm using next.js with ant design and in the `next.config.js` I need to use

```
module.exports = withAntdLess({ ... })
```

So, how can I add `withOptimizedImages` in the config? :(

Thanks!

[Iva Kop](https://hashnode.com/@IvaKop)

[Sep 28, 2021](https://hashnode.com/posts/image-optimization-for-static-nextjs-sites/604cae1e37d84907f1327f94/comment/61521a97040ee87236950749#reply-61532647414f78089df3af0c)

Hi, Oscar! Did you try [next-compose-plugins](https://www.npmjs.com/package/next-compose-plugins)?

[Minnel H](https://hashnode.com/@HDreamDev)

[Aug 6, 2021](https://hashnode.com/posts/image-optimization-for-static-nextjs-sites/604cae1e37d84907f1327f94/comment/610cfbc3528eff11aea87552)

Hi Iva Kop. Thanks for your article. It will be really helpful for many developers. 👏 I am trying to optimize all images that use on the website developed by next js. For exporting into HTML, I used the "next-optimized-images" package. It works correctly with static require (e.g: require('/src/demo.png') as your above article. But for all of the Images, I have to import images with require dynamically (e.g: const imagePath = '/src/demo.png'; require(imagePath) in a loop ). If I debug the imagePath variable its value is correct but it does not work. I know we can not use the "require" dynamically, if so is there any other way to run the package("next-optimized-images")? Could you help me or advise anything? 🙏 Thanks. Minnel.

[Iva Kop](https://hashnode.com/@IvaKop)

[Sep 28, 2021](https://hashnode.com/posts/image-optimization-for-static-nextjs-sites/604cae1e37d84907f1327f94/comment/610cfbc3528eff11aea87552#reply-615327159c8bfd08f5ba746c)

Hi Minnel! The topic seems to be discussed in [this GitHub issue](https://github.com/cyrilwanner/next-optimized-images/issues/16). Hope it helps!

[Minnel H](https://hashnode.com/@HDreamDev)

[Sep 28, 2021](https://hashnode.com/posts/image-optimization-for-static-nextjs-sites/604cae1e37d84907f1327f94/comment/610cfbc3528eff11aea87552#reply-6153a1ea414f78089df3b8ca)

[Iva Kop](https://hashnode.com/@IvaKop) Hi Iva Kop. Thanks for your comment. 😍

[Rodrigo Barros](https://hashnode.com/@ThankYouGod)

[Mar 18, 2021](https://hashnode.com/posts/image-optimization-for-static-nextjs-sites/604cae1e37d84907f1327f94/comment/605355387081c5144a4bcc36)

EU TE AMO VOCE SALVOU MEU EMPREGO, BRASILSILSIL
