我刚刚开始学习React, Facebook通过提供以下现成的项目来帮助简化初始设置。
如果我必须安装框架项目,我必须在命令行中键入npx create-react-app my-app。
我想知道为什么Facebook在Github有npx create-react-app my-app而不是npm create-react-app my-app?
我刚刚开始学习React, Facebook通过提供以下现成的项目来帮助简化初始设置。
如果我必须安装框架项目,我必须在命令行中键入npx create-react-app my-app。
我想知道为什么Facebook在Github有npx create-react-app my-app而不是npm create-react-app my-app?
当前回答
NPX:
从https://www.futurehosting.com/blog/npx-makes-life-easier-for-node-developers-plus-node-vulnerability-news/:
Web developers can have dozens of projects on their development machines, and each project has its own particular set of npm-installed dependencies. A few years back, the usual advice for dealing with CLI applications like Grunt or Gulp was to install them locally in each project and also globally so they could easily be run from the command line. But installing globally caused as many problems as it solved. Projects may depend on different versions of command line tools, and polluting the operating system with lots of development-specific CLI tools isn’t great either. Today, most developers prefer to install tools locally and leave it at that. Local versions of tools allow developers to pull projects from GitHub without worrying about incompatibilities with globally installed versions of tools. NPM can just install local versions and you’re good to go. But project specific installations aren’t without their problems: how do you run the right version of the tool without specifying its exact location in the project or playing around with aliases? That’s the problem npx solves. A new tool included in NPM 5.2, npx is a small utility that’s smart enough to run the right application when it’s called from within a project. If you wanted to run the project-local version of mocha, for example, you can run npx mocha inside the project and it will do what you expect. A useful side benefit of npx is that it will automatically install npm packages that aren’t already installed. So, as the tool’s creator Kat Marchán points out, you can run npx benny-hill without having to deal with Benny Hill polluting the global environment. If you want to take npx for a spin, update to the most recent version of npm.
其他回答
NPM是用来安装包的工具,NPX是用来执行包的工具。 如果你想通过npm运行一个包,那么你必须在你的包中指定这个包。并在本地安装它。 npx-一个包不需要安装就可以执行。它是一个npm包运行器,所以如果任何包还没有安装,它会自动安装它们。
NPM: NPM代表Node包管理器,是Node.js的默认包管理器。它由Isaac Z. Schlueter开发,最初发布于2010年1月12日。它完全是用JavaScript编写的。它由一个命令行客户端npm组成,用于管理所有node.js包和模块。当node.js被安装时,它被包含在安装中。
npm run your-package-name
NPX是一个用于执行包的工具。
NPX是npm的首字母缩写,NPX包是npm自带的,所以当你在5.2.0以上安装npm时,NPX会自动安装。
它是一个npm包运行器,可以从npm注册表中执行任何你想要的包,甚至不需要安装那个包。npx在单次使用包中非常有用。如果你在5.2.0以下安装了npm,那么npx不会安装在你的系统中。
执行以下命令确定是否安装了npx:
npx -v
如果未安装npx,则可以执行以下命令。
npm install -g npx
使用npx执行包:
npx your-package-name
下面是一个使用npx创建应用程序的示例
NPX create-react-app project-name——template all
npm - JavaScript包管理器,就像:pip (Python), Maven (Java), NuGet (.NET), Composer (PHP), RubyGems (Ruby),…
NPX—运行包的命令而不显式地安装它。
用例:
您不希望既全局安装包,也不希望在本地安装包。 您没有全局安装它的权限。 只是想测试一些命令。 有时,您希望在包中有一个脚本命令(生成、转换某些东西……)。Json来执行一些东西,而不需要将这些包作为项目的依赖项安装。
语法:
npx [options] [-p|--package <package>] <command> [command-arg]...
软件包可选:
npx -p uglify-js uglifyjs --output app.min.js app.js common.js
+----------------+ +--------------------------------------------+
package (optional) command, followed by arguments
例如:
Start a HTTP Server : npx http-server
Lint code : npx eslint ./src
# Run uglifyjs command in the package uglify-js
Minify JS : npx -p uglify-js uglifyjs -o app.min.js app.js common.js
Minify CSS : npx clean-css-cli -o style.min.css css/bootstrap.css style.css
Minify HTML : npx html-minifier index-2.html -o index.html --remove-comments --collapse-whitespace
Scan for open ports : npx evilscan 192.168.1.10 --port=10-9999
Cast video to Chromecast : npx castnow http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerFun.mp4
更多关于命令的内容:
https://docs.npmjs.com/files/package.json#bin https://github.com/mishoo/UglifyJS2/blob/master/package.json#L17
NPX:
从https://www.futurehosting.com/blog/npx-makes-life-easier-for-node-developers-plus-node-vulnerability-news/:
Web developers can have dozens of projects on their development machines, and each project has its own particular set of npm-installed dependencies. A few years back, the usual advice for dealing with CLI applications like Grunt or Gulp was to install them locally in each project and also globally so they could easily be run from the command line. But installing globally caused as many problems as it solved. Projects may depend on different versions of command line tools, and polluting the operating system with lots of development-specific CLI tools isn’t great either. Today, most developers prefer to install tools locally and leave it at that. Local versions of tools allow developers to pull projects from GitHub without worrying about incompatibilities with globally installed versions of tools. NPM can just install local versions and you’re good to go. But project specific installations aren’t without their problems: how do you run the right version of the tool without specifying its exact location in the project or playing around with aliases? That’s the problem npx solves. A new tool included in NPM 5.2, npx is a small utility that’s smart enough to run the right application when it’s called from within a project. If you wanted to run the project-local version of mocha, for example, you can run npx mocha inside the project and it will do what you expect. A useful side benefit of npx is that it will automatically install npm packages that aren’t already installed. So, as the tool’s creator Kat Marchán points out, you can run npx benny-hill without having to deal with Benny Hill polluting the global environment. If you want to take npx for a spin, update to the most recent version of npm.