Skip to main content
Version: 10.x

pnpm dlx

别名:pnpxpnpm dlx 的别名

¥Aliases: pnpx is an alias for pnpm dlx

从注册表中获取包,而不将其安装为依赖,热加载它,并运行它公开的任何默认命令二进制文件。

¥Fetches a package from the registry without installing it as a dependency, hotloads it, and runs whatever default command binary it exposes.

例如,要在任何地方使用 create-react-app 来引导 React 应用,而不需要将其安装在另一个项目下,你可以运行:

¥For example, to use create-react-app anywhere to bootstrap a react app without needing to install it under another project, you can run:

pnpm dlx create-react-app ./my-app

这将从注册表中获取 create-react-app 并使用给定的参数运行它。

¥This will fetch create-react-app from the registry and run it with the given arguments.

你还可以指定你想要使用的软件包的确切版本:

¥You may also specify which exact version of the package you'd like to use:

pnpm dlx create-react-app@next ./my-app

选项

¥Options

--package <name>

运行命令之前要安装的包。

¥The package to install before running the command.

示例:

¥Example:

pnpm --package=@pnpm/meta-updater dlx meta-updater --help
pnpm --package=@pnpm/meta-updater@0 dlx meta-updater --help

可以提供多个包进行安装:

¥Multiple packages can be provided for installation:

pnpm --package=yo --package=generator-webapp dlx yo webapp --skip-install

--allow-build

已添加于:v10.2.0

¥Added in: v10.2.0

允许在安装期间运行安装后脚本的软件包名称列表。

¥A list of package names that are allowed to run postinstall scripts during installation.

示例:

¥Example:

pnpm --allow-build=esbuild my-bundler bundle

默认情况下,dlx 执行的实际包允许运行安装后脚本。因此,如果在上面的例子中 my-bundler 必须在执行前构建,它将被构建。

¥The actual packages executed by dlx are allowed to run postinstall scripts by default. So if in the above example my-bundler has to be built before execution, it will be built.

--shell-mode, -c

在 shell 内运行命令。在 UNIX 上使用 /bin/sh,在 Windows 上使用 \cmd.exe

¥Runs the command inside of a shell. Uses /bin/sh on UNIX and \cmd.exe on Windows.

示例:

¥Example:

pnpm --package cowsay --package lolcatjs -c dlx 'echo "hi pnpm" | cowsay | lolcatjs'

--silent, -s

仅打印执行命令的输出。

¥Only the output of the executed command is printed.