Rollup plugin that loads .env files and replaces process.env references at build time. Current stable version is 0.5.1. Released irregularly, with the last release in 2023. It integrates with @rollup/plugin-replace under the hood for environment variable substitution. Supports multiple .env files with environment-specific overrides (e.g., .env.production.local). Unlike runtime dotenv packages, this plugin performs compile-time replacement, which can improve performance and security. No browser or client-side usage. Only supports CommonJS requires? Note: This plugin does not support dynamic access like process.env[VAR]. Shipping TypeScript types.
npm install rollup-plugin-dotenvVerified import paths — ran on the pinned version, not inferred.
Basic Rollup configuration using rollup-plugin-dotenv to replace process.env references with values from .env files.
Use static property access for env vars that should be replaced at build time.
Avoid using process.env.VAR names that might conflict with other strings in your code.
Upgrade Rollup to >= 1.20.0 or use older version of the plugin.
Use runtime dotenv for development if needed, or configure Rollup to replace only in production builds.
Ensure you call dotenv() without arguments or with valid options. If you pass custom options, they must include valid keys.
Use import dotenv from 'rollup-plugin-dotenv' or const dotenv = require('rollup-plugin-dotenv').Ensure .env files exist in the current working directory or set the cwd option to the correct directory.