Npm and Bower are both dependency management tools.(Npm和Bower都是依赖管理工具。)
But the main difference between both is npm is used for installing Node js modules but bower js is used for managing front end components like html, css, js etc .(但两者之间的主要区别是npm用于安装Node js模块,但是bower js用于管理前端组件,如html,css,js等 。)
A fact that makes this more confusing is that npm provides some packages which can be used in front-end development as well, like grunt
and jshint
.(让这更令人困惑的一个事实是,npm提供了一些可以用于前端开发的软件包,比如grunt
和jshint
。)
These lines add more meaning(这些行增加了更多含义)
Bower, unlike npm, can have multiple files (eg .js, .css, .html, .png, .ttf) which are considered the main file(s).(与npm不同,Bower可以有多个文件(例如.js,.css,.html,.png,.ttf),这些文件被认为是主文件。)
Bower semantically considers these main files, when packaged together, a component.(Bower在语义上将这些主文件打包在一起时,它们是一个组件。)
Edit : Grunt is quite different from Npm and Bower.(编辑 : Grunt与Npm和Bower完全不同。)
Grunt is a javascript task runner tool.(Grunt是一个javascript任务运行器工具。) You can do a lot of things using grunt which you had to do manually otherwise.(你可以使用grunt做很多事情,否则你必须手动完成。) Highlighting some of the uses of Grunt:(强调Grunt的一些用法:)
- Zipping some files (eg zipup plugin)(压缩一些文件(例如zipup插件))
- Linting on js files (jshint)(Lins on js files(jshint))
- Compiling less files (grunt-contrib-less)(编译较少的文件(grunt-contrib-less))
There are grunt plugins for sass compilation, uglifying your javascript, copy files/folders, minifying javascript etc.(有sass编译的grunt插件,uglifying你的javascript,复制文件/文件夹,缩小javascript等。)
Please Note that grunt plugin is also an npm package.(请注意,grunt插件也是一个npm包。)
Question-1(问题1)
When I want to add a package (and check in the dependency into git), where does it belong - into package.json or into bower.json(当我想添加一个包(并将依赖项检入git),它在哪里 - 属于package.json或bower.json)
It really depends where does this package belong to.(这真的取决于这个包属于哪里。)
If it is a node module(like grunt,request) then it will go in package.json otherwise into bower json.(如果它是一个节点模块(如grunt,request)那么它将在package.json中进入bower json。)
Question-2(问题2)
When should I ever install packages explicitly like that without adding them to the file that manages dependencies(什么时候我应该像这样明确地安装包而不将它们添加到管理依赖项的文件中)
It does not matter whether you are installing packages explicitly or mentioning the dependency in .json file.(无论是显式安装包还是提及.json文件中的依赖项都无关紧要。)
Suppose you are in the middle of working on a node project and you need another project, say request
, then you have two options:(假设您正在处理节点项目,并且需要另一个项目,比如request
,那么您有两个选择:)
- Edit the package.json file and add a dependency on 'request'(编辑package.json文件并在'request'上添加依赖项)
- npm install(npm安装)
OR(要么)
- Use commandline:
npm install --save request
(使用命令行: npm install --save request
)
--save
options adds the dependency to package.json file as well.(--save
选项也将依赖项添加到package.json文件中。)
If you don't specify --save
option, it will only download the package but the json file will be unaffected.(如果未指定--save
选项,则只会下载程序包,但json文件不受影响。)
You can do this either way, there will not be a substantial difference.(你可以这样做,不会有实质性的区别。)