简体   繁体   English

NPM造成全球混乱

[英]NPM install global confusion

npm install css-sprite --save

npm install css-sprite -g

What does 2 different command above do? 上面两个不同的命令有什么作用? I know -g is global, but why do you want it to be global? 我知道-g是全局的,但是为什么要使其成为全局的呢? What's --save? 什么是-保存?

  • npm install MODULE --save will add the module's name and information directly into your package.json file. npm install MODULE --save将模块的名称和信息直接添加到package.json文件中。 It is a shortcut from writing the dependency first in your package.json and then doing npm install (which reads the file and installs all dependencies). 这是一种捷径,它是先在package.json编写依赖项,然后再执行npm install (读取文件并安装所有依赖项)。

  • npm install MODULE -g will make sure the module is accessible everywhere in your system, not just in your project's directory. npm install MODULE -g将确保模块可以在系统中的任何位置访问,而不仅仅是在项目目录中。 The purpose of this, is that some modules can be used in a "standalone" way, without NodeJS. 这样做的目的是可以在没有NodeJS的情况下以“独立”方式使用某些模块。 For example, module Jade is a template engine for HTML. 例如,模块Jade是HTML的模板引擎。 I write all my HTML files in Jade (syntax), and then I call jade myfile.jade to render HTML files. 我用Jade(语法)编写所有HTML文件,然后调用jade myfile.jade呈现HTML文件。 I can only call jade freely in the console after installing it globally through npm. 通过npm全局安装后,我只能在控制台中自由调用jade。

https://docs.npmjs.com/cli/install https://docs.npmjs.com/cli/install

According to the npm documentation : 根据npm文档:

--save: Package will appear in your dependencies. --save:软件包将出现在您的依赖项中。

The --global argument will cause npm to install the package globally rather than locally. --global参数将导致npm在全局而非本地安装软件包。

--save will modify the package.json and add the dependencies in it. --save将修改package.json并在其中添加依赖项。

--global will install the module as a global module. --global将模块安装为全局模块。 Every nodejs application on your machine will have this module. 您计算机上的每个nodejs应用程序都将具有此模块。 On most computers, the global folder of npm is in the PATH. 在大多数计算机上,npm的全局文件夹位于PATH中。 So when you install a module as --global, you can use in a command line. 因此,当您将模块安装为--global时,可以在命令行中使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM