下面的内容浅显易懂,适合初级前端工程师观看前端
此篇主要内容是讲,如何使用WebStorm控制台下载、删除依赖包,和npm,bower一些指令的使用方法。node
学习这篇文章前,须要将node.js先安装好。git
地址:http://nodejs.cn/github
通常来讲前端开发工做中,或多或少会用到一些依赖包,之前的开发人员若是要用的话,就获得网上处处找,而后下各类插件,极大浪费了时间,而且删除的时候也麻烦。npm
后来twitter推出了bower,它主要是一个包管理工具,简单来讲就是一个静态资源共享平台。前端须要用到的插件基本均可以在里面下载,这就极大方便了开发。json
因而咱们就从下载bower开始吧。前端工程师
1.打开WS,点击图中标记处,打开控制台工具
2.输入npm install -g bower 敲回车学习
npm nodejs安装包管理器this
install 安装
-g 全局(安装)
bower 依赖包的名称
[问题:开始我打 npm install -g bower 的时候 说 npm command not found !
回答:都说了要装node.js才能往下学习啦!!!]
这是我输入之后控制台返回的信息
意思是我已经安装过了,因此我如今须要把它删除,而后从新下
这里插一下删除安装包的方法
3.输入npm rm -g bower (这样个人bower就被删除了)
rm remove(移除)的意思
而后我再从新步骤1(重复部分就不上图了)完成后,输入bower init
会提示你输入一些基本信息,根据提示按回车或者空格便可,而后会生成一个bower.json
文件,用来保存该项目的配置。
而后bower就安装好了!
下面就能够开始下安装包了,好比人见人夸的angular
angular我已经下过了,
因此仍是老办法,我得先删除,因此先看看怎么删除依赖包
--save 意思就是要将这个文件连同json文件中的也一块儿删干净,否则下次你重载bower它但是还会回来的!
下面即是个人json文件,能够看出个人依赖包只有jQuery和select2,没有angular,说明删干净了噢!
如今开始下载angular
控制台输入bower install --save angular ,如图,这样angular就下好了。
--save (将它加入到json文件中)
如果对bower 和 insta指令很感兴趣。能够在控制台中输入bower i -h或npm i -h,会出现不少指令的使用方法,供你参考学习。
D:\开发\WebstormProjects\demo>bower i -h
Usage:
bower install [<options>]
bower install <endpoint> [<endpoint> ..] [<options>]
Options:
-F, --force-latest Force latest version on conflict
-f, --force If dependencies are installed, it reinstalls all installed components. It also forces installation even when there are non-bower directories with the same name in the components directory. Also bypasses
the cache and overwrites to the cache anyway.
-h, --help Show this help message
-p, --production Do not install project devDependencies
-S, --save Save installed packages into the project's bower.json dependencies
-D, --save-dev Save installed packages into the project's bower.json devDependencies
-E, --save-exact Configure installed packages with an exact version rather than semver
Additionally all global options listed in 'bower help' are available
Description:
Installs the project dependencies or a specific set of endpoints.
Endpoints can have multiple forms:
- <source>
- <source>#<target>
- <name>=<source>#<target>
Where:
- <source> is a package URL, physical location or registry name
- <target> is a valid range, commit, branch, etc.
- <name> is the name it should have locally.
D:\开发\WebstormProjects\demo>npm i -h
npm install (with no args, in package dir)
npm install [<@scope>/]<pkg>
npm install [<@scope>/]<pkg>@<tag>
npm install [<@scope>/]<pkg>@<version>
npm install [<@scope>/]<pkg>@<version range>
npm install <folder>
npm install <tarball file>
npm install <tarball url>
npm install <git:// url>
npm install <github username>/<github project>
alias: npm i
common options: [--save|--save-dev|--save-optional] [--save-exact]
D:\开发\WebstormProjects\demo>