Mac安装Grunt的配置及使用

  |   Mac

如果你想要简化你的工作,想办法让自己的时间变得短一些。Grunt是JavaScript世界的构建工具,因为它拥有丰富的插件。你也可以利用Grunt自动完成任何事,并花费最少的代价。是不是很震撼吧?我只能说其实Grunt就是强大的吧。


安装及配置

Grunt插件是通过npm安装并管理,npm是Node.js的包管理器。

安装之前,请确保你是否安装过npm,如果已经安装了npm的话,就可以开始安装Grunt。

安装 CLI

npm install -g grunt-cli

例如Mac终端器命令

localhost:~ jinghua$ sudo npm install -g grunt-cli 
Password:
/usr/local/bin/grunt -> /usr/local/lib/node_modules/grunt-cli/bin/grunt
grunt-cli@1.2.0 /usr/local/lib/node_modules/grunt-cli
├── grunt-known-options@1.1.0
├── resolve@1.1.7
├── nopt@3.0.6 (abbrev@1.0.9)
└── findup-sync@0.3.0 (glob@5.0.15)
localhost:~ jinghua$ mkidr testgrunt
-bash: mkidr: command not found
localhost:~ jinghua$ mkdir -p testgrunt
localhost:~ jinghua$ cd testgrunt
localhost:testgrunt jinghua$ sudo 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: (testgrunt) 
version: (1.0.0) 
description: 测试gurnt
entry point: (index.js) 
test command: test
git repository: 
keywords: grunt
author: yuyi
license: (ISC) 
About to write to /Users/jinghua/testgrunt/package.json:

{
  "name": "testgrunt",
  "version": "1.0.0",
  "description": "测试gurnt",
  "main": "index.js",
  "scripts": {
    "test": "test"
  },
  "keywords": [
    "grunt"
  ],
  "author": "yuyi",
  "license": "ISC"
}


Is this ok? (yes) yes


接下来Gruntfile.js创建

localhost:testgrunt jinghua$ touch package.json Gruntfile.js
touch: package.json: Permission denied