# rollup-plugin-dotenv

> Rollup plugin that loads available .env files and replaces the defined variables with their values

Latest version **0.5.1** (published 2024-04-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install rollup-plugin-dotenv
pnpm add rollup-plugin-dotenv
yarn add rollup-plugin-dotenv
bun add rollup-plugin-dotenv
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.1 |
| Published | 2024-04-15 |
| First published | 2018-06-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=14 |
| Dependencies | 2 |
| Unpacked size | 8.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 33 |
| Author | Mateusz Burzyński |
| Maintainers | andarist |
| Keywords | rollup, dotenv |

## Links

- npm: https://www.npmjs.com/package/rollup-plugin-dotenv
- Repository: https://github.com/Andarist/rollup-plugin-dotenv
- Homepage: https://github.com/Andarist/rollup-plugin-dotenv#readme
- Issues: https://github.com/Andarist/rollup-plugin-dotenv/issues
- npm.io page: https://npm.io/package/rollup-plugin-dotenv

## Dependencies (2)

- [dotenv](https://npm.io/package/dotenv.md) ^16.0.3
- [@rollup/plugin-replace](https://npm.io/package/@rollup/plugin-replace.md) ^5.0.1

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 0.5.1 (latest) — 2024-04-15
- 0.5.0 — 2023-05-30
- 0.4.1 — 2022-10-27
- 0.4.0 — 2022-09-15
- 0.3.0 — 2020-05-21
- 0.2.0 — 2018-08-22
- 0.1.0 — 2018-06-20

## README

# rollup-plugin-dotenv

## Installation

```console
npm install rollup-plugin-dotenv
```

## Usage

Create a `rollup.config.js` [configuration file](https://www.rollupjs.org/guide/en/#configuration-files) and import the plugin:

```js
import dotenv from "rollup-plugin-dotenv"

export default {
  input: "src/index.js",
  output: [
    dir: "dist/build"
  ],
  plugins: [
    dotenv()
  ]
}
```

create your `.env` file in the root of your project.

```bash
# .env
FOO=bar
```

so you can use FOO in your javascript files.

```js
// src/index.js
console.log(process.env.FOO)
```

your env variables will be replaced by their values in your bundled file.

```js
// dist/build/index.js
console.log('bar')
```

if you want to know more about the principle and restrictions of replacement, please read [@rollup/plugin-replace](https://www.npmjs.com/package/@rollup/plugin-replace) notes.

## Options

You can specify the options below.

### `cwd`

Type: `String`
Default: `"."`

directory in which to search for env files.

### `envKey`

Type: `String`
Default: `"NODE_ENV"`

key used to search for .env files by node environment

Rollup will merge env vars located at

```
[
  `.env.${process.env[envKey]}.local`,
  `.env.${process.env[envKey]}`,
  '.env.local',
  '.env',
]
```

so if you are in `prod`, rollup will search in

```
['.env.prod.local', '.env.prod', '.env.local', '.env']
```

and merge the result.

[LICENSE (MIT)](/LICENSE)

---
_Source: https://npm.io/package/rollup-plugin-dotenv · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
