您的位置:首页 > Web前端 > JavaScript

javascript前端工具------自动化构建工具Grunt

2016-05-15 11:55 639 查看
Grunt官网网址:http://gruntjs.com/

首先要明白grunt的作用是什么:它能帮我们做一些简单的、重复性的、程序员一般都不愿自己去做的工作,比如说单元测试、代码的压缩和代码的校验等等。它能更好的帮助我们管理项目。

1.安装Grunt

首先必须安装了nodejs,然后使用npm命令安装:

npm install grunt-cli -g


cli的意思是command line interface(命令行接口)

2.项目中运用Grunt

(1)项目中需要在package.json配置Grunt;有3种方式创建package.json

- 可以在终端使用命令创建package.json,不过要先安装grunt-init;

- 通过npm inti

- 通过手写文件

在这里,我通过第二种方式创建package.json.

E:\f>npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help json` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg> --save` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
name: (f) test
version: (1.0.0) 0.1.0
description: My test project
entry point: (index.js) index.html
test command:
git repository:
keywords:
author:
license: (ISC)
About to write to E:\f\package.json:

{
"name": "test",
"version": "0.1.0",
"description": "My test project",
"main": "index.html",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}

Is this ok? (yes) yes


创建之后是没有把相关的依赖加进去的,想要加进去,可以通过以下方式:

npm install grunt --save-dev


(2)要有Gruntfile.js或者Gruntfile.coffee

未完待续。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  grunt