With npm, you can pass random arguments like this:
npm run build --foo="bar"
You can then access foo
value this way:
process.env.npm_config_foo
Is it possible to do the same with pnpm? I looked in their docs but couldn't find anything on that. I tried something like this but getting unknown flag error
pnpm build --foo=bar
I am not sure why it throws an error. Sounds like a bug. However, this will work:
pnpm run build --foo=bar
But it will not create the npm_config_foo
env variable. It will just append the option to the executed script. So if your build script is webpack
, then pnpm will run:
webpack --foo=bar
So, it is basically like running npm run build -- --foo=bar
. Or like running yarn build --foo=bar
You can read about this also in the pnpm docs: https://pnpm.io/cli/run#options