安装grunt-cli shell
Note that installing grunt-cli
does not install the Grunt task runner! The job of the Grunt CLI is simple: run the version of Grunt which has been installed next to a Gruntfile
. This allows multiple versions of Grunt to be installed on the same machine simultaneously.
grunt-cli只是一个命令行shell,简单来说就是grunt命令。grunt-cli并不是真正的grunt task runner,真正的task runner是随项目安装的。因此,不同的项目可以使用不同的grunt版本。具体来说,在项目的根目录下,创建package.json,在其中配置grunt的dependency,然后执行npm install,就会得到grunt task runner
启动grunt构建
Assuming that the Grunt CLI has been installed and that the project has already been configured with apackage.json
and a Gruntfile
, it's very easy to start working with Grunt:
- Change to the project's root directory.
- Install project dependencies with
npm install
. - Run Grunt with
grunt
.
安装了grunt-cli之后,在项目根目录下准备好package.json和Gruntfile.js文件,再依次执行npm install和grunt即可
其中,npm install将下载安装项目依赖的包(当然必须包括grunt),grunt将读取Gruntfile.js,执行grunt构建。Gruntfile.js就相当于ant.xml
Gruntfile.js的组成
A Gruntfile
is comprised of the following parts:
- The "wrapper" function
- Project and task configuration
- Loading Grunt plugins and tasks
- Custom tasks