Importing local custom scripts
Answered
Dwarf Hotot posted this in #help-forum
Dwarf HototOP
guys I have a question, I'm trying to import a custom scripts that I created in the same folder of my components who need that, I'm using the <Script> tag from nextjs but continously tells me that the file is not found.
9 Replies
put the script in the public folder
Answer
Dwarf HototOP
it's a must?
cause I were more comfortable to put it in the same folder of the components it's related to
<Script /> is for external scripts, which mean you either (1) specify a URL pointing to that script or (2) use the entire script content as a string.
public folder is an easy way to do (1).
if you want to keep in the same folder, you need to get either the file content or the file URL when importing the script file, which means you need to write a custom webpack config to handle module resolution for this specific script file. so while it's technically doable, do you think it's worth it?
public folder is an easy way to do (1).
if you want to keep in the same folder, you need to get either the file content or the file URL when importing the script file, which means you need to write a custom webpack config to handle module resolution for this specific script file. so while it's technically doable, do you think it's worth it?
Dwarf HototOP
oh, okay
thank you very muchj
anyway, do you have some suggestions about folder management?
not much, no. this is all what you need to know https://nextjs.org/docs/app/building-your-application/routing/colocation
after all this is your project. there is no right or wrong. there is only what works for you and what doesn't. i change my folder structure once in a while too.
after all this is your project. there is no right or wrong. there is only what works for you and what doesn't. i change my folder structure once in a while too.
Dwarf HototOP
okay, thank you very much