博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
npx 运行react_npx节点包运行器
阅读量:2505 次
发布时间:2019-05-11

本文共 3401 字,大约阅读时间需要 11 分钟。

npx 运行react

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

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

If you don’t want to install npm, you can

如果您不想安装npm,则可以

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 :

使用@指定版本,并将其与结合使用:

npx node@6 -v #v6.14.3npx 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 gist, for example:

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

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.

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

翻译自:

npx 运行react

转载地址:http://dvqgb.baihongyu.com/

你可能感兴趣的文章
白话插件框架原理
查看>>
Using Bytecode Outline to View Java bytecode in Eclipse
查看>>
overflow: hidden用法,不仅仅是隐藏溢出
查看>>
javaweb编程思想
查看>>
Linux中cd test和cd /test以及类似命令的区别
查看>>
[BS-26] UIView、pop和Core Animation区别
查看>>
dubbo_rpc原理
查看>>
Java设计模式之《模板模式》及使用场景
查看>>
Linux编程入门
查看>>
坑爹的箭头函数
查看>>
Python 环境搭建
查看>>
IOS 在不打开电话服务的时候,可以响应服务器的推送消息,从而接收服务器的推送消息...
查看>>
置顶的博客
查看>>
ionic2 native app 更新用户头像暨文件操作
查看>>
SQL Server R2 地图报表制作(一)
查看>>
ZeroMQ——一个轻量级的消息通信组件
查看>>
JavaScript中数组和json的复制
查看>>
新概念4-30
查看>>
新概念4-40
查看>>
Android开发之Handler
查看>>