Next.js Discord

Discord Forum

Run scripts during build time

Answered
"use php" posted this in #help-forum
Open in Discord
I want to run scripts during build time, like for each individual page
Since I'm using cloudflare images, Is there any way, like during build, I can get all the sizes which nextjs has given to the user in srcset, and put it in my allowlist?

Runtime of all my pages are edge if it affects something


So I want to run something similar to getStaticProps during build time
Answered by joulev
write a script, run it in the build step
{
  "scripts": {
    "build": "node scripts/do-stuff.js && next build"
  }
}
View full answer

4 Replies

I need to basically execute for each route, a different one
Only solution I found is to use unstable cache, which'll execute only on first request.

I didn't find anything during build time, as I'm using edge runtime
Answer
output in json and simply import that json to your page