1 //Custom Tasks2Module.exports =function(grunt) {3 //project Configuration4 varHTTP = require (' http ');5 varQS = require (' querystring ');6 varFs=require ("FS");7 8 functionWrite (name,temp) {9Fs.writefile ("./release/" +name,temp, "UTF8",function(err) {Ten if(err) { OneGrunt.log.error (' BODY: ' +err); A } - }); - } the - Grunt.initconfig ({ - minjs:{ -Version: "0.9.7", +RootPath: "./online/", -RESOURCE:[{SRC: "Rongimclient.js", NameList: "Rongimclient.min.js,rongimclient-0.9.7.min.js", Operate: "Pack"}, +{src: "emoji-0.9.2.js", NameList: "Rongimclient.emoji-0.9.2.min.js", Operate: "Pack"}, A{src: "protobuf.js", NameList: "Protobuf.min.js", Operate: "Uglify"}, at{src: "swfobject.js", NameList: "Swfobject.min.js", Operate: "Uglify"}, -{src: "voice-0.9.1.js", NameList: "Rongimclient.voice-0.9.1.min.js", Operate: "Pack"}, -{src: "xhrpolling.js", NameList: "Xhrpolling.min.js", Operate: "Uglify"}], -ENV: "Release" - } - }); inGrunt.registertask (' Minjs ', ' Custom compression js file ',function () { - to This. Async (); + -Grunt.log.writeln (' Processing task ... '); the * $ varOptions = {Panax NotoginsengHostname: ' Tool.lu ', -Port:80, thePath: '/js/ajax.html ', +Method: ' POST ', A headers: { the' Content-type ': ' application/x-www-form-urlencoded ' + } - }; $Grunt.config ("Minjs.resource"). ForEach (function(x) { $Fs.readfile (Grunt.config ("Minjs.rootpath") + x.src, "UTF8",function(err,data) { - if(err) { - Grunt.log.error (err); the return; - }Wuyi if(Grunt.config ("minjs.env") = = = "Release"){ theData=data.replace (/\["Navurl-debug" \]/g, "[\" navurl-release\ "]"); - } Wu varPost_data = { - Code:data, About operate:x.operate $ }; - varreq = http.request (options,function(res) { -Res.setencoding (' UTF8 '); - varChunk= ""; ARes.on (' Data ',function(data) { +chunk+=data; the }); -Res.on ("End",function(){ $ vartemp=Json.parse (chunk); the if(temp.status===true){ theX.namelist.split (","). ForEach (function(name) { the write (name,temp.text); the }); -}Else{ in Grunt.log.error (temp.message); the } the }) About }); theReq.on (' Error ',function(e) { theGrunt.log.error (' Problem with request: ' +e.message); the }); + Req.write (Qs.stringify (Post_data)); - req.end (); the });Bayi }); the the }); -};
View Code
Grunt custom Task Implementation JS file obfuscation and encryption