npx 运行react_npx节点包运行器

npx 运行react

In this post, I want to introduce a very powerful command that’s been available in npm starting version 5.2, released in July 2017: npx.

在这篇文章中,我想介绍一个非常强大的命令,一直在提供NPM启动5.2版本,在2017年7月发布:NPX。

If you don’t want to install npm, you can install npx as a standalone package

如果您不想安装npm,则可以将npx作为独立软件包安装

npx lets you run code built with Node and published through the npm registry.

npx允许您运行使用Node构建并通过npm注册表发布的代码。

轻松运行本地命令 (Easily run local commands)

Node developers used to publish most of the executable commands as global packages, in order for them to be in the path and executable immediately.

节点开发人员过去通常将大多数可执行命令发布为全局包,以使它们立即位于路径中并可执行。

This was a pain because you could not really install different versions of the same command.

这很痛苦,因为您无法真正安装同一命令的不同版本。

Running npx commandname automatically finds the correct reference of the command inside the node_modules folder of a project, without needing to know the exact path, and without requiring the package to be installed globally and in the user’s path.

运行npx commandname自动在项目的node_modules文件夹中找到该命令的正确引用,而无需知道确切的路径,也不需要在全局和用户路径中安装该软件包。

无需安装的命令执行 (Installation-less command execution)

There is another great feature of npm, which is allowing to run commands without first installing them.

npm另一个重要功能是无需先安装命令即可运行命令。

This is pretty useful, mostly because:

这非常有用,主要是因为:

1) you don’t need to install anything 2) you can run different versions of the same command, using the syntax @version

1)您不需要安装任何内容2)您可以使用@version语法运行同一命令的不同版本

A typical demonstration of using npx is through the cowsay command. cowsay will print a cow saying what you wrote in the command. For example:

使用npx典型演示是通过cowsay命令。 cowsay将打印出一头母牛,说出您在命令中写的内容。 例如:

cowsay "Hello" will print

cowsay "Hello"将打印

_______
< Hello >
 -------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

Now, this if you have the cowsay command globally installed from npm previously, otherwise you’ll get an error when you try to run the command.

现在,如果您之前已从npm全局安装了cowsay命令,那么这是要执行的操作,否则,将在运行命令时收到错误消息。

npx allows you to run that npm command without having it installed locally:

npx允许您运行该npm命令,而无需将其本地安装:

npx cowsay "Hello"

will do the job.

会做的工作。

Now, this is a funny useless command. Other scenarios include:

现在,这是一个有趣的无用命令。 其他方案包括:

  • running the vue CLI tool to create new applications and run them: npx vue create my-vue-app

    运行vue CLI工具以创建新应用程序并运行它们: npx vue create my-vue-app

  • creating a new React app using create-react-app: npx create-react-app my-react-app

    使用create-react-app创建一个新的React应用: npx create-react-app my-react-app

and many more.

还有很多。

Once downloaded, the downloaded code will be wiped.

一旦下载,下载的代码将被擦除。

使用不同的Node版本运行一些代码 (Run some code using a different Node version)

Use the @ to specify the version, and combine that with the node npm package:

使用@指定版本,并将其与node npm软件包结合使用:

npx node@6 -v #v6.14.3
npx node@8 -v #v8.11.3

This helps to avoid tools like nvm or the other Node version management tools.

这有助于避免使用nvm等工具或其他Node版本管理工具。

直接从URL运行任意代码段 (Run arbitrary code snippets directly from a URL)

npx does not limit you to the packages published on the npm registry.

npx并不限制您使用npm注册表中发布的软件包。

You can run code that sits in a GitHub gist, for example:

您可以运行位于GitHub要点中的代码,例如:

npx https://gist.github.com/zkat/4bc19503fe9e9309e2bfaa2c58074d32

Of course, you need to be careful when running code that you do not control, as with great power comes great responsibility.

当然,在运行不受控制的代码时,您需要格外小心,因为强大的功能带来了巨大的责任。

翻译自: https://flaviocopes.com/npx/

npx 运行react

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值