env-management-in-lib-mode #6804
Replies: 3 comments 1 reply
-
One trick you could consider is using a non-breaking whitespace character for your library: https://vitejs.dev/guide/env-and-mode.html#production-replacement But I think a better option is to revisit the entrypoint or API interface of your hook/component library:
This way, you don't need to worry about hardcoding or inlining any config values. You also decouple the responsibility of variable handling from your library to the consuming runtime. |
Beta Was this translation helpful? Give feedback.
-
Finally after waking whole night, i found a quick hack for the env managements in lib mode. 😅 i defined import.meta in vite.config.ts as it is. and here you go 🚀 |
Beta Was this translation helpful? Give feedback.
-
I tried @IrfanAli17899's approach but it didn't seem to work for me, my However, following the tip on Environment Variables in the Vite Building for Production Guide to use
Thanks for the idea! 😀 |
Beta Was this translation helpful? Give feedback.
-
Hi Everyone, I hope everyone is doing great.
I am currently building a component/hooks library using vite build.lib and typescript :react: .
i am expecting that when this library will run in a real project it will get some envs through import.meta.env on runtime but its not happening when i make the build of lib it reads the envs and hardcodes it in the build, can anyone help me in this usecase?
this is my-lib/config/index.ts file which defines all the envs that i am expecting to be passed on runtime and will be used by my lib on runtime.
this is my-lib/vite.config.ts for the lib compilation.
now here is the real problem, this is my-lib/build/index.es.js
Beta Was this translation helpful? Give feedback.
All reactions