Easily add the import.meta types from vite and vitest to your TypeScript project
npm install vite-envThis package exists to make it easy to get the right behavior for import.meta
when using vite and (optionally) vitest.
``sh`
$ pnpm add -D vite-env
Add this to your tsconfig:
`json`
{
"compilerOptions": {
"types": ["vite-env"]
}
}
Once you've done that, you can use import.meta features from Vite and Vitest:
`ts
if (import.meta.env.DEV) {
console.log("DEV");
}
if (import.meta.vitest) {
const { describe, it } = import.meta.vitest;
}
`
- import.meta.env.DEVimport.meta.env.PROD
- import.meta.env.MODE
- import.meta.vitest`
-
For the most part, this package pulls in types published by vite and vitest. At
the moment, the best practices for doing this correctly have been in flux and
not always easy to figure out.
If this changes and the guidance becomes stable and easy to find, this package
will no longer need to exist.
MIT © Yehuda Katz and Starbeam
Contributors