Linux command
yarn-dlx 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Run a package without installing
yarn dlx [create-react-app] [my-app]
Run a specific package version
yarn dlx [gatsby]@[4.0.0] new [my-site]
Run a command from a different package
yarn dlx -p [typescript] tsc --version
Run with quiet output
yarn dlx -q [cowsay] "Hello"
Run a command with multiple package dependencies
yarn dlx -p [typescript] -p [ts-node] ts-node --transpile-only -e "console.log('hello')"
Scaffold a Next.js app
yarn dlx create-next-app [my-app]
说明
yarn dlx runs a package in a temporary environment without permanently installing it. This is the Yarn equivalent of npx, useful for one-off commands like project scaffolding tools. The command downloads the specified package to a temporary location, executes the package's binary scripts within the current working directory, and cleans up afterward. It's commonly used with generators like create-react-app, create-next-app, and gatsby that create new project structures. By default, yarn dlx uses the command name to determine which package to install. Use -p to specify a different package when the command name differs from the package name.
参数
- -p _package_, --package _package_
- Designate which package to install before executing the command. Can be specified multiple times to install multiple packages.
- -q, --quiet
- Suppress detailed installation logs and report only essential error messages.
FAQ
What is the yarn-dlx command used for?
yarn dlx runs a package in a temporary environment without permanently installing it. This is the Yarn equivalent of npx, useful for one-off commands like project scaffolding tools. The command downloads the specified package to a temporary location, executes the package's binary scripts within the current working directory, and cleans up afterward. It's commonly used with generators like create-react-app, create-next-app, and gatsby that create new project structures. By default, yarn dlx uses the command name to determine which package to install. Use -p to specify a different package when the command name differs from the package name.
How do I run a basic yarn-dlx example?
Run `yarn dlx [create-react-app] [my-app]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -p _package_, --package _package_ do in yarn-dlx?
Designate which package to install before executing the command. Can be specified multiple times to install multiple packages.