JSPM

esbuild-plugin-environment

0.2.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6797
  • Score
    100M100P100Q119650F
  • License MIT

esbuild plugin to define process.env variables

Package Exports

  • esbuild-plugin-environment
  • esbuild-plugin-environment/package.json
  • esbuild-plugin-environment/plugin

Readme

esbuild-plugin-environment

Build Status

Install

npm install esbuild-plugin-environment -D

Usage

Add the plugin to your esbuild plugins.

Example esbuild.config.cjs file:

const { environmentPlugin } = require('esbuild-plugin-environment');

module.exports = () => {
  const config = {
    bundle: true,
    sourcemap: true,
    platform: 'node',
    target: 'es2022',
    format: 'esm',
    outputFileExtension: '.mjs',
    environment: {},
    concurrency: 4,
    watch: {
      pattern: ['./src/**'],
      ignore: ['dist', 'node_modules'],
    },
    plugins: [
      // process.env key => default value
      environmentPlugin({
        BUILD_TIMESTAMP: new Date().toISOString(),
      }),
      // Array of process.env keys
      environmentPlugin(['PWD', 'npm_package_version']),
    ],
  };

  return config;
};