rollup-plugin-inject-env

0.1.0 • Public • Published

rollup-plugin-inject-env

Statically inject variables from the dotenv file. Reuse the familiar process.env.MY_VAR substitution token. Environment variables are inserted as strings.

// .env
MY_API_KEY=12345

// source
const x = process.env.MY_API_KEY;

// generated code
const x = '12345';

usage

Add it to your rollup config plugins list.

Optionally pass include, exclude, and/or envFilePath minimatch patterns in the options parameter.

node_modules/** is always ignored.

import injectEnv from 'rollup-plugin-inject-env';
export default {
  input: 'src/index.ts',
  output: {
    file: 'bundle.js',
    format: 'iife',
    sourcemap: true
  },
  plugins: [
    injectEnv({
      // include: "include/sources/minimatch",
      // exclude: "exclude/sources/minimatch",
      // envFilePath: "path/to/.env",
    }),
  ]
};

motivation

Code and configuration should be separate. Servers can store configuration in environment variables, but clients (like web browsers) do not always get that luxury. One way to solve the problem is statically injecting configuration into the bundle at compile-time with Rollup.

Package Sidebar

Install

npm i rollup-plugin-inject-env

Weekly Downloads

143

Version

0.1.0

License

MIT

Unpacked Size

3.87 kB

Total Files

3

Last publish

Collaborators

  • xmclark