基于bower、grunt搭建angularjs项目

来源:互联网 发布:js防水涂料使用什么布 编辑:程序博客网 时间:2024/05/22 05:11

参考:http://blog.csdn.net/ch717828/article/details/50339087
http://www.cnblogs.com/ricky52529/p/4079514.html

说明一下,本机开发环境已准备好,包括nodejs、bower以及全局grunt都已经安装好了。

首先新建文件夹,并进入该文件夹目录

1、生成 package.json 文件
这个 package.json 文件其实是 Node.js 来描述一个项目的文件,JSON 格式。
使用 命令来生成 package.json

npm init

它会问我们一些问题,我们可以按需回答,也可以全部使用默认值,以后改起来也很容易。
生成的package.json如下

{  "name": "isearch",  "version": "1.0.0",  "description": "",  "main": "index.js",  "scripts": {    "test": "echo \"Error: no test specified\" && exit 1"  },  "author": "",  "license": "ISC"}

2、安装 Grunt

npm install grunt --save-dev 

将使用npm下载grunt插件,它们将保存到项目根目录下的node_modules目录下。

后面的–save-dev参数是说,把这个插件信息,同时添加到package.json的devDependencies中

"devDependencies": {      "grunt": "^1.0.1"    } 

由于grunt仅在开发阶段使用,所以使用–save-dev。如果是运行时使用的,则用–save
3、创建Grunt配置文件
创建一个Grunt的配置文件 Gruntfile.js,内容如下

module.exports = function(grunt) {    grunt.initConfig({    });  };

4、为bower生成配置文件bower.json

bower  init

生成bower.json

{  "name": "isearch",  "description": "",  "main": "index.js",  "authors": [    "xx <xx@trs.com.cn>"  ],  "license": "ISC",  "homepage": "",  "ignore": [    "**/.*",    "node_modules",    "bower_components",    "test",    "tests"  ]}

5、使用bower安装AngularJS

bower install angularjs --save grunt

安装成功后,在bower.json增加了angularjs

"dependencies": {    "angular": "angularjs#^1.6.6"  }