-
Describe the bugI don't know whether I should file this under bug or feature request since I'm not sure if it's the intended behavior or not, but I'm unable to use ENV variables in static Reproductionhttps://codesandbox.io/p/devbox/vite-env-var-in-static-files-bug-7c7l4t Steps to reproduce
System Info(CodeSandbox environment)
System:
OS: Linux 6.1 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
CPU: (2) x64 AMD EPYC
Memory: 2.20 GB / 4.01 GB
Container: Yes
Shell: Unknown
Binaries:
Node: 20.9.0 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 9.8.1 - /usr/local/bin/npm
pnpm: 8.10.2 - /usr/local/share/npm-global/bin/pnpm
npmPackages:
vite: ^5.0.8 => 5.0.11 Used Package Managernpm LogsNo response Validations
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I think the easiest way is to write a script or Vite plugin that runs after the Vite build that replaces the |
Beta Was this translation helpful? Give feedback.
import.meta.env.*
can only work for code that Vite processes, so if you want to use it in static files (which aren't processed by Vite), you need to manually change it yourself.I think the easiest way is to write a script or Vite plugin that runs after the Vite build that replaces the
import.meta.env.*
in/dist/static-script.js
.