-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Description
What is the problem this feature would solve?
When bundling a project that uses an index.html pointing to a module like main.tsx, there is currently no way to inject env variables directly into the client bundle when running bun index.html. unlike bun build for JS/TS, bun index.html does not accept the --define flag, so I cannot even manually replace values like process.env.PORT. This makes it impossible to inject run-time env configuration into the HTML bundle and client-side code.
Bun supports .env auto-loading for server environments. The expectation is that the requested feature should also leverage Bun’s .env auto-loading mechanism, so variables from a .env file would be automatically available for injection into the client bundle or via --define during HTML bundling. (limited to public env varaibles)
What is the feature you are proposing to solve the problem?
I propose to add support for either:
- Direct injection of env variables (such as process.env.*) into the client HTML bundle
bun has multiple configuration to decide which env can be bundled and how
https://bun.com/docs/bundler#env
--defineflag inbun index.html, so users could manually map values (e.g.,bun --define process.env.PORT="'3000'" index.html). should and could also have worked here.
we need way to
- be able to use env variables in client bundle run via bun HTML bundler
- be able to define how the env are embedded following the env bundling rules.
What alternatives have you considered?
Manually handling env replacement before building, but this is error-prone and does not leverage Bun’s intended features.