esbuild-env-plugin
v1.0.0
Published
A Plugin for ESBuild that allows importing .env files directly into process.env or as object
Downloads
1
Readme
esbuild-env-plugin
A plugin that enables importing .env files. If the build platform is 'node', variables will be added to process.env
Installation
You can install the esbuild-env-plugin
package using npm or yarn:
npm install esbuild-env-plugin --save-dev
or
yarn add esbuild-env-plugin --dev
Usage
To use the esbuild-env-plugin
, follow these steps:
- Import the plugin at the top of your esbuild configuration file:
const { EnvPlugin } = require('esbuild-env-plugin'); // OR
import { EnvPlugin } from 'esbuild-env-plugin';
- Add the plugin to your esbuild configuration:
const buildContext = await context({
entryPoints: ['./index.ts'],
plugins: [EnvPlugin()],
outdir: './dist',
bundle: true,
format: 'esm',
platform: 'node',
tsconfig: './tsconfig.json',
logLevel: 'info'
});
- In your code, you can now import .env files as object:
//Import worker. It is important to include the file ending, otherwise its imported as module not as worker
import env from './example.env';
env.MY_VAR // or if platform is node
process.env.MY_VAR
License
This project is licensed under the MIT License - see the LICENSE file for details.