gruntfile.js配置如下:
module.exports = function(grunt){
Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
clean: {//删除文件
build: {
src: ["webapp/hello/js/dev/all.js"]
}
},
concat: {//合并文件
options: {
separator: ';',
stripBanners: false,
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
dist: {
src: ['webapp/hello/js/dev/func/*.js'],
dest: 'webapp/hello/js/dev/all.js',
},
},
modernizr: {//检测css3\h5支持情况
dist: {
"parseFiles": true,
"customTests": [],
"devFile": "webapp/hello/js/modernizr-dev.js",
"dest": "webapp/hello/js/moderniz.js",
"tests": [
"ambientlight",
"applicationcache",
"audio",
"batteryapi",
"blobconstructor",
"canvas",
"canvastext",
"contenteditable",
"contextmenu",
"cookies",
"cors",
"cryptography",
"customprotocolhandler",
"customevent",
"dart",
"dataview",
"emoji",
"eventlistener",
"exiforientation",
"flash",
"forcetouch",
"fullscreen",
"gamepads",
"geolocation",
"hashchange",
"hiddenscroll",
"history",
"htmlimports",
"ie8compat",
"indexeddb",
"indexeddbblob",
"input",
"search",
"inputtypes",
"intl",
"json",
"ligatures",
"olreversed",
"mathml",
"notification",
"pagevisibility",
"performance",
"pointerevents",
"pointerlock",
"postmessage",
"proximity",
"queryselector",
"quotamanagement",
"requestanimationframe",
"serviceworker",
"svg",
"templatestrings",
"touchevents",
"typedarrays",
"unicoderange",
"unicode",
"userdata",
"vibrate",
"video",
"vml",
"webintents",
"animation",
"webgl",
"websockets",
"xdomainrequest",
"adownload",
"audioloop",
"audiopreload",
"webaudio",
"lowbattery",
"canvasblending",
[
"todataurljpeg",
"todataurlpng",
"todataurlwebp"
],
[
"canvaswinding"
],
"getrandomvalues",
"cssall",
"cssanimations",
"appearance",
"backdropfilter",
"backgroundblendmode",
"backgroundcliptext",
"bgpositionshorthand",
"bgpositionxy",
[
"bgrepeatspace",
"bgrepeatround"
],
"backgroundsize",
"bgsizecover",
"borderimage",
"borderradius",
"boxshadow",
"boxsizing",
"csscalc",
"checked",
"csschunit",
"csscolumns",
"cubicbezierrange",
"display-runin",
"displaytable",
"ellipsis",
"cssescape",
"cssexunit",
"cssfilters",
"flexbox",
"flexboxlegacy",
"flexboxtweener",
"flexwrap",
"fontface",
"generatedcontent",
"cssgradients",
"csshairline",
"hsla",
[
"csshyphens",
"softhyphens",
"softhyphensfind"
],
"cssinvalid",
"lastchild",
"cssmask",
"mediaqueries",
"multiplebgs",
"nthchild",
"objectfit",
"opacity",
"overflowscrolling",
"csspointerevents",
"csspositionsticky",
"csspseudoanimations",
"csspseudotransitions",
"cssreflections",
"regions",
"cssremunit",
"cssresize",
"rgba",
"cssscrollbar",
"scrollsnappoints",
"shapes",
"siblinggeneral",
"subpixelfont",
"supports",
"target",
"textalignlast",
"textshadow",
"csstransforms",
"csstransforms3d",
"preserve3d",
"csstransitions",
"userselect",
"cssvalid",
"cssvhunit",
"cssvmaxunit",
"cssvminunit",
"cssvwunit",
"willchange",
"wrapflow",
"classlist",
[
"createelementattrs",
"createelement-attrs"
],
"dataset",
"documentfragment",
"hidden",
"microdata",
"mutationobserver",
"bdi",
"datalistelem",
"details",
"outputelem",
"picture",
[
"progressbar",
"meter"
],
"ruby",
"template",
"time",
[
"texttrackapi",
"track"
],
"unknownelements",
"es5array",
"es5date",
"es5function",
"es5object",
"es5",
"strictmode",
"es5string",
"es5syntax",
"es5undefined",
"es6array",
"es6collections",
"contains",
"generators",
"es6math",
"es6number",
"es6object",
"promises",
"es6string",
[
"devicemotion",
"deviceorientation"
],
"oninput",
"filereader",
"filesystem",
"capture",
"fileinput",
"directory",
"formattribute",
"localizednumber",
"placeholder",
"requestautocomplete",
"formvalidation",
"sandbox",
"seamless",
"srcdoc",
"apng",
"imgcrossorigin",
"jpeg2000",
"jpegxr",
"sizes",
"srcset",
"webpalpha",
"webpanimation",
[
"webplossless",
"webp-lossless"
],
"webp",
"inputformaction",
"inputformenctype",
"inputformmethod",
"inputformtarget",
"beacon",
"lowbandwidth",
"eventsource",
"fetch",
"xhrresponsetypearraybuffer",
"xhrresponsetypeblob",
"xhrresponsetypedocument",
"xhrresponsetypejson",
"xhrresponsetypetext",
"xhrresponsetype",
"xhr2",
"scriptasync",
"scriptdefer",
"speechrecognition",
"speechsynthesis",
"localstorage",
"sessionstorage",
"websqldatabase",
"stylescoped",
"svgasimg",
"svgclippaths",
"svgfilters",
"svgforeignobject",
"inlinesvg",
"smil",
"textareamaxlength",
"bloburls",
"datauri",
"urlparser",
"videoautoplay",
"videoloop",
"videopreload",
"webglextensions",
"datachannel",
"getusermedia",
"peerconnection",
"websocketsbinary",
[
"atobbtoa"
],
"framed",
"matchmedia",
"blobworkers",
"dataworkers",
"sharedworkers",
"transferables",
"webworkers"
],
"options": [
"domPrefixes",
"prefixes",
"addTest",
"atRule",
"hasEvent",
"mq",
"prefixed",
"prefixedCSS",
"prefixedCSSValue",
"testAllProps",
"testProp",
"testStyles",
"html5shiv",
"setClasses"
],
"uglify": true
}
},
uglify: {//压缩文件
options: {
stripBanners: false,
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
build: {
src: ['webapp/hello/js/dev/all.js'],
dest: 'webapp/hello/js/min/all.min.js'
}
},
watch: {
js: {
files: ['webapp/hello/js/dev/func/*.js'],
tasks:['default'],
options: {livereload:false}
},
}
});
// 加载包含 "uglify" 任务的插件。
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks("grunt-modernizr");
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', ['clean','concat','uglify']);
grunt.registerTask('watcher',['watch']);
}
package.json配置如下:
{
"name": "hellworld",
"version": "1.0.0",
"description": "hello world",
"main": "index.js",
"scripts": {
"test": "test"
},
"author": "cheonghu",
"license": "ISC",
"devDependencies": {
"grunt": "*",
"grunt-contrib-jshint": "*",
"grunt-contrib-nodeunit": "*",
"grunt-contrib-uglify": "*",
"grunt-contrib-cssmin":"*",
"grunt-contrib-sass":"*",
"grunt-contrib-watch":"*",
"grunt-contrib-clean":"*",
"grunt-contrib-concat":"*",
"grunt-cssc":"*",
"grunt-htmlhint":"*",
"grunt-modernizr":"*",
"matchdep":"*"
}
}