-
-
Save linkgod/6316853 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function(grunt){ | |
grunt.initConfig({ | |
pkg:grunt.file.readJSON("package.json"), | |
less:{ | |
//必包含的less文件,合并到内的,合并的文件的内容会比component内的文件内容先出现 | |
options:{ | |
concat:true, //合并 | |
paths:"source/less",//路径 | |
imports:{ | |
less:["basic.less"]//需要合并的less文件名 | |
}, | |
banner:"/*\n@author:<%=pkg.author%>\n@date:<%=grunt.template.today('yyyy-mm-dd')%>\n*/" | |
}, | |
//其他组件 | |
components:{ | |
//编译的css文件 | |
files:{ | |
"static/css/main.css":"source/less/main.less"//key为编译后的路径,value为需要编译的文件 | |
} | |
}, | |
//启动压缩 | |
yuicompress:{ | |
files:{ | |
"static/css/min/main.css":"static/css/main.css" | |
}, | |
options:{ | |
yuicompress:true//这个地方必须为true 才会压缩 | |
} | |
} | |
}, | |
//jade模板使用 | |
jade:{ | |
html: { | |
src: ['source/jade/*.jade'], | |
dest: 'static', | |
options: { | |
client: false | |
} | |
} | |
}, | |
//javascript代码检查 | |
jshint:{ | |
all:["source/js/*.js"] | |
}, | |
//压缩js代码 | |
uglify:{ | |
options:{ | |
report:"gzip" //可以查看输出后的大小比例 | |
}, | |
build:{ //编译参数 | |
files:{ | |
// "dest/test.js":"source/js/index.js", | |
// "dest/test1.js":"source/js/index.js" | |
} | |
} | |
}, | |
//require压缩 | |
requirejs: { | |
compile: { | |
options: { | |
name:"main", //main.js | |
baseUrl: "source/js", | |
out: "static/js/build.js" | |
} | |
} | |
}, | |
watch:{//监听变化 | |
less:{ | |
files:["source/less/*.less"], | |
tasks:['less:components','less:yuicompress'] | |
}, | |
jade:{ | |
files:['<%=jade.html.src%>'], | |
tasks:['jade'] | |
}, | |
require:{ | |
files:['source/js/*.js'], | |
tasks:['requirejs'] | |
} | |
} | |
}); | |
grunt.loadNpmTasks("assemble-less"); | |
grunt.loadNpmTasks("grunt-jade"); | |
grunt.loadNpmTasks('grunt-contrib-requirejs'); | |
grunt.loadNpmTasks('grunt-contrib-jshint'); | |
grunt.loadNpmTasks('grunt-contrib-uglify'); | |
grunt.loadNpmTasks("grunt-contrib-watch"); | |
grunt.registerTask("default",["less",'jade','uglify',"watch"]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment