How to modify NextJs build to add a node script to the flow?
Unanswered
Cinnamon posted this in #help-forum
CinnamonOP
I have a .js file which I want to run with
If I use
node filename.js after the build completed, it copies a needed file from node_modules to the .next folder.If I use
npm run dev it creates the .next folder each time and deletes my .js file3 Replies
Peterbald
I think you have to write the filename.js code as a funtion of Next.js project. And when you call this function, then you can call. I think it is the better solution rather than coping .js file to node module.
I hope it is helpful for you
I hope it is helpful for you
@Cinnamon I have a .js file which I want to run with `node filename.js` after the build completed, it copies a needed file from node_modules to the .next folder.
If I use `npm run dev` it creates the .next folder each time and deletes my .js file
This is an XY problem. What exactly are you trying to achieve? Why do you need to copy to .next?
.next is not supposed to be written on. Its structure is not documented hence not covered by semver, it can change at any moment and your entire flow would break if you rely on its internal structure. Also as you see, next dev writes to it a lot so what you are trying to do (move a file to .next) is pretty much impossible
.next is not supposed to be written on. Its structure is not documented hence not covered by semver, it can change at any moment and your entire flow would break if you rely on its internal structure. Also as you see, next dev writes to it a lot so what you are trying to do (move a file to .next) is pretty much impossible
CinnamonOP
React PDFJS required to copy the worker to the build folder, but I found another solution