jed / esbuild-plugin-env

An esbuild plugin that exports the current environment as a module

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

esbuild-plugin-env

This is an esbuild plugin that exports the current environment as a module, allowing you to embed environment variables in your build.

Usage

Here's an example of usage in Deno. Let's say you have a module secret.js that exports a secret:

export {SECRET} from 'env'

You can bundle it like this:

import {build} from 'https://deno.land/x/esbuild@v0.13.15/mod.js'
import env from 'https://deno.land/x/esbuild_plugin_env@v1.0.0/mod.js'

Deno.env.set('SECRET', '********')

await build({
  bundle: true,
  format: 'esm',
  entryPoints: ['secret.js'],
  plugins: [env]
})

This will result in this code:

var SECRET = "********";
export {
  SECRET
};

About

An esbuild plugin that exports the current environment as a module

License:MIT License


Languages

Language:JavaScript 100.0%