乐闻世界logo
搜索文章和话题

How to pass arbitrary argument with pnpm

1个答案

1

When using pnpm to execute commands, if you need to pass arbitrary parameters to scripts or commands, you can typically add these parameters directly after the command. However, if you need to pass parameters to an npm script run via pnpm, you must add -- before the parameters to ensure they are correctly passed.

For example, if you have an npm script named start and you want to pass some arbitrary parameters to it, you can do this:

sh
pnpm start -- --user=yourname --port=8080

In this example, --user=yourname and --port=8080 are the parameters to be passed to the start script. The -- ensures that pnpm passes the subsequent parameters unchanged to start, rather than consuming them itself.

Another example: if you use the pnpm exec command to run a tool and need to pass parameters to that tool, you typically do not need --. For instance:

sh
pnpm exec some-tool --option=value

In this case, --option=value is directly passed to some-tool.

Note that pnpm's behavior may differ slightly from npm and yarn, but all of them support using the -- delimiter to pass additional parameters.

2024年6月29日 12:07 回复

你的答案