grunt Getting Started

安装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:

  1. Change to the project's root directory.
  2. Install project dependencies with npm install.
  3. 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的组成

Gruntfile is comprised of the following parts:

  • The "wrapper" function
  • Project and task configuration
  • Loading Grunt plugins and tasks
  • Custom tasks
grunt任务分层管理,首先是plugin,然后是task,最后是target。举例:grunt-contrib-uglify这个插件,其中定义了uglify task,针对这个task可以指定不同的target(目的是应用不同的配置参数)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值