Multiple scripts without leaking into eachother.
Is it possible to have multiple script tags/files with separate require statements without raising an error that the thing is already defined. having all the imports in one script works but then the autocomplete doesn't work.
I suppose changing it to let would work but sounds like a bad way to do things
for example:
9 Replies
Don't know how else to put it or how to search for it
isn't this what build tools are made to solve? I've never really looked into configuring build tools, I kinda skipped that step and went from basic vanilla JS straight to using frameworks with build tools preconfigured, but I'm pretty sure that's what build tools would do
I have no idea, would prefer not to use a framework
build tools aren't frameworks though 🙂
yeah ik
as for googling it, I'd suggest searching for "javascript require once". PHP has a function for this called require_once, that detects if a file has already been included, and there's a lot of PHP devs writing javascript too, so there's some suggestions
If I had to roll my own, and controlled all the code, I'd put each require in an if-statement that checked if the variable for that require was already defined
or even maybe
this might be the best solution i guess
it's not something I'd do if I didn't write all the code that might have those requires, but it seems like you do
not sure if
process || require('process');
or process ?? require('process');
would work better though, I'd probably try the nullish coalescing operator firstill try giving rollup a try first