nuxt icon indicating copy to clipboard operation
nuxt copied to clipboard

Generate static files without random ids

Open sebsonjura opened this issue 2 years ago • 2 comments

We have a s3 deploy running that simply syncs the contents of a build to the bucket.

Is your feature request related to a problem? Please describe.

With each build, it leaves an old version in the static folder from a previous build. Over time we are accumulating a lot of folders with random ids in static. Depending on the amount of builds and page contents, this can be a great number of data.

Describe the solution you'd like

I would be able to host all new files under static directly or re build into the same id with every build, since we have very fine control over headers in our cdn

Describe alternatives you've considered

An alternative would be a safe way to read out the latest random id and have a nightly build job delete old files from our deploy S3 Bucket.

Additional context

  • we are using latest nuxt
  • deploy is with AWS codebuild
  • deployed to a s3 bucket
  • Files served via cloudfront

sebsonjura avatar May 26 '21 09:05 sebsonjura

Hmmm... use CleanWebpackPlugin on one of hooks + https://nuxtjs.org/docs/2.x/configuration-glossary/configuration-build#filenames?

andig89 avatar May 27 '21 06:05 andig89

I found a way to make this number stay the same on each build....it seems to be undocumented, but the generator uses an injected configuration value called staticAssets.version for this number. If the value is null, it results in a random number each time.

You can make it the same every time you generate by setting it in your nuxt.config.js:

  generate: {
    staticAssets: {
      version: "1",
    },
  }

In this case I used "1", but I assume that can be any valid path string. With a value here, the number won't change from build to build.

mdryden avatar Jul 10 '22 18:07 mdryden