Home > Blockchain >  How to make fixed filenames for nuxt build in production?
How to make fixed filenames for nuxt build in production?

Time:05-23

I am using nuxt with SSR inside a Docker container. Whenever I build my project for production, it generates some random names for js file chunks. This causes some issues because of the browser's cache, which tries to load not existing js files. Because these files no longer exist, I am getting a lot of not found errors for js files built in the previous deployment.

How to can I deal with this problem?

CodePudding user response:

I guess something wrong with your browser caching policy and it's not working as expected because the not found/404 status code issue is not a common thing.

In order to answer your question about the fixed chunk name for production build in Nuxt, there is a built-in method to make it work and you can learn that by following the documentation.

So to achieve this you do this in the nuxt.config.js file:

export default {
  build: {
    filenames: {
      chunk: () => '[name].js'
    }
  }
}

Be careful when using non-hashed based filenames in production as most browsers will cache the asset and not detect the changes on first load.

  • Related