-
-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Description
Clear and concise description of the problem
I would like to know what build.lib.format
is at build time.
Use case: usage information (we log which build our clients are using at runtime).
This would also be useful for anyone who would like to change some values for different builds e.g. es, cjs and esm.
Suggested solution
Ideally there should be an environment variable set in import.meta.env
for the build format e.g.
{
"BASE_URL": "/",
"MODE": "production",
"DEV": false,
"PROD": true,
"BUILD": "umd" // <----- Additional environment variable for library format
}
Alternative
Current workaround: Assuming I define process.env.VITE_LIB_TYPE=umd
in vite.config.js
I can use import.meta.env
in the code and at build it will be replaced.
// app.js
function buildType() {
return import.meta.env.VITE_LIB_TYPE || "empty"
}
// dist/app.js
function buildType() {
return "umd"
}
However this solution means I need to have two vite.config.js
files. One for each build format e.g. es and umd.
Or is there a way to define an array of configs? Or perhaps be able to add custom environment variables for each build type?
Additional context
Solves #5975
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.