.env
You can access environment variables set in a .env
file in your project root using bud.env.
Precedence
Environment variables are sourced from .env
files recursively, starting with the project root directory. The closer the file is to the project root, the higher priority it has.
So, if you have an .env
file in your project root and another in the parent directory, and both contain a value for the same key, the value from the project root will be used.
Expansion
bud.js supports expansion of environment variables. For example:
PUBLIC_API_ORIGIN=https://api.example.com
PUBLIC_API_URL=${PUBLIC_API_ORIGIN}/endpoint
Public variables
Any environment variables that are prefixed with PUBLIC_
will be available to your application code. When using variable values in your application you
must remove the PUBLIC_
prefix.
For example, setting PUBLIC_API_URL
:
PUBLIC_API_URL=https://api.example.com
Means API_URL
can be used in your application code:
const request = fetch(`${API_URL}/endpoint`)
The replacement is static and happens at build time. It is not the same as defining a global.
For example, attempting to redefine it will cause a type error:
/**
* Don't do this
*/
API_URL = 'https://api.example.com'
Configurable environment variables
Variable | Description | Related argument |
---|---|---|
BUD_BROWSERSLIST_UPDATE | Set to false in order to disable automatic updating of the browserslist database. | --browserslist-update |
BUD_CACHE | Enable or disable bud.js caching | --cache |
BUD_DEVTOOL | The devtool to use for builds | --devtool |
BUD_ESM | Enable or disable bud.js ESM output (experimental) | --esm |
BUD_HASH | Enable or disable output file hashing | --hash |
BUD_HTML | Enable HTML templating; set to a string to specify the path to a template | --html |
BUD_HOT | Enable or disable bud.js hot reloading | --hot |
BUD_IMMUTABLE | Enable or disable automated updates of dependencies when using remote modules | --immutable |
BUD_LAZY | Enable or disable lazy compilation of modules in development | --lazy |
BUD_MINIMIZE | Enable or disable code minimization | --minimize |
BUD_PATH_BASE | The path to the root directory of the bud.js project | --basedir |
BUD_PATH_STORAGE | The path to the directory where bud.js stores its data and caches | --storage |
BUD_PATH_INPUT | The path to the directory where bud.js looks for source files | --input |
BUD_PATH_OUTPUT | The path to the directory where bud.js outputs build files | --output |
BUD_PATH_PUBLIC | Directory to prepend to asset URLs (if assets are not served from web root) | --publicPath |
BUD_PROXY_URL | The URL of the proxy server to use | --proxy |
BUD_RUNTIME | Enable or disable generation of a runtime module | --runtime |
BUD_SPLIT_CHUNKS | Enable or disable splitting of modules into discrete chunks (vendor , app , etc.) | --split-chunks |
CLI
You can verify what environment variables are available to bud.js using the bud env
command:
- npm
- Yarn
- pnpm
npm run bud env
yarn bud env
pnpm run bud env