How to handle global configuration in a sveltekit library? #8938
Unanswered
paoloricciuti
asked this question in
Q&A
Replies: 1 comment
-
For the moment i fixed this by also writing an esbuild plugin that changes the content of the file during the vite optimization fase. Still not very sold on this whole way to add configuration so feel free to comment if you have better ideas |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
THE PROBLEM
For a library I'm making I have to pick some stringy values (name of events and fields). Given that this could conflict with the user app I used some difficult-to-conflict names (with the name of the library in and with load of _ and -) but I would also like to give people the opportunity to customize those. Right now I store those in an exported variable in a module. But I have to read those either client side (in a store) or server side (in a handle hooks). During build Sveltekit inline the variable into the component code so I can't just modify that variable dinamically.
MY SOLUTION
I wrote a vite plugin that take the option as input and transform that file both during dev and build mode so that it contains the provided value.
THE PROBLEM TO MY SOLUTION
In build there's no problem but I'm dev mode (I think this is the problem) vite uses native esm so it actually import the file (which is not transformed)...so if you use the plugin it breaks the dev server.
MY IDEAS ON HOW TO FIX THIS
One thing I can do is make the transformation only on build...but this means that dev and prod would be completely different and you still couldn't use those names in dev. Another thing that I have yet to try is to use the configure server hook to modify the file on the fly during the esm import request.
HOW CAN YOU HELP?
Either solving this problem or by giving me ideas on how would you handle the config thing.
Beta Was this translation helpful? Give feedback.
All reactions