1.0.0 • Published 2 years ago
esbuild-env-plugin v1.0.0
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-devor
yarn add esbuild-env-plugin --devUsage
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_VARLicense
This project is licensed under the MIT License - see the LICENSE file for details.
1.0.0
2 years ago