What's the best place to add code that is only meant to be executed once when doing a static build and has no relationship with any route? #79618
-
SummaryIf the code does not have any relationship with any route it shouldn't go in any layout or page, but because it is a static build, instrumentation.ts won't be run. Is this a bug though? Should instrumentation.ts be run when doing a static build? I couldn't find any info about it. (If this is a bug please let me know so I can create an issue for it). Anyways, I don't want to add the code to any generateStaticParams() because I am not generating any static parameter so it doesn't seem appropriate to add my code there. I don't want to add the code to any server component because it doesn't affect the output of that component. Specifically, I have a folder with some markdown files and I want to create an RSS feed. I want to create the xml file and put it in the public/ folder using this JS library. The best I can think of right now is to create a separate javascript file to do just that and modify my Please keep in mind that I worded the title of this discussion in such a way to allow for more generic answers that could apply in cases other than mine. Just in case a solution comes up but it only makes sense in the context of RSS feed generation. This way more people might benefit from this. Additional informationNo response ExampleNo response |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
It sounds like, for your use case, you could use, Though, since your use case, is totally independent from the rest of your app, running a separate script, sounds just about right too. |
Beta Was this translation helpful? Give feedback.
-
I just wanted to create an RSS feed and realized I could return the feed in the If someone else wants to create a file or something like that you can try a simialr approach and do it this way. I don't like using |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
I just wanted to create an RSS feed and realized I could return the feed in the
GET
method ofsrc/app/rss.xml/route.ts
instead.If someone else wants to create a file or something like that you can try a simialr approach and do it this way.
I don't like using
next.config.js
because from what I've seen it gets executed more than once when building the static site. And I don't like creating and running a separate script either because I am deploying my site to github pages using a Github Action that runsnext build
instead ofnpm build
. I could change that easily but I think it makes more sense to find a JS file in the project to execute my code to make sure it gets executed once even if I …