关于css和js压缩和合并的方法,记得我在前端面试题目中有写道。方法很多,今天主要介绍grunt方法。
使用前提
grunt是基于node的,要在你电脑上使用grunt,电脑上必须已安装node环境。具体node环境的安装和搭建。centos请看,windows安装相对简单,下载安装包安装就可以了。关于mac的安装,后面有时间在详细介绍。
新建package.json
package.json放在根目录下,它包含了该项目的一些元信息,如项目名称、描述、版本号,插件等。
{
"name": "haorooms.com",
"version": "v0.1.0",
"devDependencies": {
"grunt": "~0.4.5",
"grunt-contrib-jshint": "~0.10.0",
"grunt-contrib-nodeunit": "~0.4.1",
"grunt-contrib-uglify": "~0.5.0",
"grunt-contrib-concat": "~0.5.1",
"grunt-contrib-cssmin": "~0.12.3",
"grunt-htmlhint": "~0.9.2"
}
}