Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nicolaspadari/vite-plugin-envloader
Automatically inject import.meta.env variables into process.env
https://github.com/nicolaspadari/vite-plugin-envloader
Last synced: about 1 month ago
JSON representation
Automatically inject import.meta.env variables into process.env
- Host: GitHub
- URL: https://github.com/nicolaspadari/vite-plugin-envloader
- Owner: NicolaSpadari
- License: mit
- Created: 2022-05-24T12:38:56.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-09-02T08:01:35.000Z (over 2 years ago)
- Last Synced: 2024-12-09T03:49:02.631Z (about 1 month ago)
- Language: TypeScript
- Homepage:
- Size: 198 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.txt
Awesome Lists containing this project
README
vite-plugin-envloader
Automatically inject `import.meta.env` variables into `process.env`
## Why?
Vite.js provides its own mechanism (meta env) for exposing environment variables through `import.meta.env`, but hostings like Netlify can't import variables defined in `import.meta.env`. [Here is the issue](https://github.com/vitejs/vite/issues/562)
This plugin injects environment variables in `process.env` by configuring the `define` option.
## Installation
Install the package as a development dependency:
```sh
npm i -D vite-plugin-envloader
```## Usage
Add this to your plugin list in the vite config file:
```js
import { defineConfig } from "vite"
import EnvLoader from "vite-plugin-envloader"export default defineConfig({
plugins: [
// ...
EnvLoader(),
// ...
],
});
```Variables defined in the `.env` file like:
```js
VITE_API_KEY="12345"
```Will be available in online hostings through `process.env.VITE_API_KEY`, while still allowing you to use `import.meta.env.VITE_API_KEY` in your code.
## License
This library is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).