Using variables in npm run scripts (package (a)rauschma/env-var must be installed locally or globally):
{
"scripts": {
"hi": "env-var echo {{npm_package_config_hi}}"
},
"config": {
"hi": "HELLO"
}
}
Works on Windows and Unix:
npm run hi
More information: https://exploringjs.com/nodejs-shell-scripting/ch_package-scripts.html#using-environment-variables-in-package-scripts
@rauschma if you are using pnpm, there's `shell-emulator` configuration option: https://pnpm.io/cli/run#shell-emulator. It lets you `DEFINE_ENVS=before script` like you'd do in regular POSIX shell. Yarn does use it by default. Kinda wish npm adopted that (probably as an option, to stay backwards compatible).