[5.0 beta 13] Issue with define replacement using esbuild #14783
Labels
p4-important
Violate documented behavior or significantly improves performance (priority)
regression
The issue only appears after a new release
Describe the bug
I am an author of npm package and in my published package it contains expression like
import.meta.env.VITE_API_ORIGIN
so my downstream user can use environment variable to override it. I publish my package using vite and I use thedefine: {"import.meta.env.VITE_API_ORIGIN": "import.meta.env.VITE_API_ORIGIN"}
in thevite.config.ts
to preserve this expression during transpilation. This works well in v4 and v5 beta until the breaking change in #11151 and I have not found a workaround yet. I have tried using@rollup/plugin-replace
but also no luck there.Reproduction
https://stackblitz.com/edit/vitejs-vite-yht5de?file=vite.config.ts,src%2Findex.ts,package.json,dist%2Findex.js&terminal=dev
Steps to reproduce
Run
yarn
followed byyarn build
Then go to the
dist/index.js
fileWhen using vite 4.5.0, the output is
My users who import this package can use a .env file to change this variable.
When using vite 5.0.0-beta.13, the output becomes
The difference here is
import.meta.env
expression disappears and my downstream users can no longer use environment variable to perform replacement in the library.System Info
Used Package Manager
yarn
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: