var c = {rootpath: ' src ',//project folder OutputPath: ' Output ',//file compiled output directory Revpath: ' Manifest ',//rev Map file directory Appjs: ' AP P.js ',//Run JS homepage: ' index.html ', cssfolderpaths: [' CSS '],//need to compress the CSS directory jsfolderpaths: [' model '],//need to compress the JS directory Ngjsfolderpaths: [' app ', ' common ', ' directives ', ' filters '],//need to compress Ngjs directory htmlfolderpaths: [' app ', ' layout '], fi Lterfolderpaths: [' Frameworks ', ' images ']};var root = function (path) {if (path) return C.rootpath + '/' + path return c.rootpath;}; var output = function (path) {if (path) return C.outputpath + '/' + path return c.outputpath;} var fs = require (' FS '), var path = require (' path '), var gulp = require ("Gulp"), clean = require (' Gulp-clean '), ngannotate = Require (' gulp-ng-annotate '),//compression Ngjs util = require (' Gulp-util '), filter = require (' Gulp-filter '), Ngmin = require (' G Ulp-ngmin '), Stripdebug = require (' Gulp-strip-debug '), minifyhtml = require ("gulp-minify-html"),//compressed HTML minify = Requi Re ("gulp-minifY-css "),//compression CSS uglify = require (" gulp-uglify "),//Compression code rename = require (" Gulp-rename "),//Rename concat = require (" Gulp-con Cat "),//merge code Sourcemaps = require (" Gulp-sourcemaps "), rev = require (" Gulp-rev "),//file name plus MD5 suffix revreplace = require (" Gulp -rev-replace "),//path substitution merge = require (" Merge-stream ");//import Command Gulp.task (' Run ', [' clear '], function () {SetTimeout (fu Nction () {Gulp.run ([' Filter ', ' CSS ', ' HTML ', ' global ', ' Model ', ' ngjs '], function () {var manifest = gulp.src ("./" + C.revpath + '/*.json '); Return gulp.src ([Root (C.homepage)]). Pipe (Revreplace ({manifest:manifest }). Pipe (Gulp.dest (C.outputpath)); }); }, 2000); });//all directories that do not need to be compressed and merged Gulp.task (' Filter ', function () {return C.filterfolderpaths.map (function (CPath) {return Gul P.SRC ([Root (CPath + '/** ')]). Pipe (gulp.Dest (Output (CPath))); });});/ /Compression Cssgulp.task (' CSS ', function () {var] tasks = C.cssfolderpaths.map (function (CPath) {return gulp.src ([Root (c Path + '/**/*.css '). Pipe (Minify ()). Pipe (rev ()). Pipe (Gulp.dest (Output (CPath))). Pi PE (rev.manifest (CPath + '. JSON ')). Pipe (Gulp.dest ('./' + C.revpath)); }); return merge (tasks);}); /compress htmlgulp.task (' HTML ', function () {var] tasks = C.htmlfolderpaths.map (function (CPath) {return gulp.src ([roo T (CPath + '/**/*.html ')]). Pipe (Minifyhtml ()). Pipe (Gulp.dest (Output (CPath))); }); return merge (tasks);}); /compress the global JS file and replace the reference Gulp.task in index.html (' Global ', function () {return gulp.src ([Root ('/*.js ')]). PIPE (Ngannotat E ()). Pipe (Ngmin ({dynamic:false})). Pipe (Stripdebug ()). Pipe (Uglify ({outsourcemap:false}))//Compression NGJS . Pipe (Concat (C.APPJS)). Pipe (rev ())//file name plus MD5 suffix. Pipe (gulp.dest (C.outputpath)). Pipe (Rev.manifeSt (' Global.json '))//Generate Manifest.json. Pipe (Gulp.dest ('./' + C.revpath);}); /Compress Modelgulp.task (' model ', function () {var] tasks = C.jsfolderpaths.map (function (CPath) {return gulp.src ([roo T (CPath + '/**/*.js ')]). Pipe (Uglify ()). Pipe (rev ()). Pipe (Gulp.dest (Output (CPath))). Pipe (Rev.manifest (CPath + '. JSON ')). Pipe (Gulp.dest ('./' + C.revpath)); }); return merge (tasks);}); /Compress Ngjsgulp.task (' Ngjs ', function () {var tasks = C.ngjsfolderpaths.map (function (CPath) {return gulp.src ([roo T (CPath + '/**/*.js ')]). Pipe (Uglify ()). Pipe (rename (function path) {if (path.basename.to Lowercase (). IndexOf (' login ') >-1) {path.basename = Path.basename.toLowerCase (); } return path; }). Pipe (rev ()). Pipe (Gulp.dest (Output (CPath))). Pipe (Rev.manifest (CPath + '. JSON ')) . Pipe (Gulp.dest ('./' + C.revpath)); }); return merge (tasks);}); /cleanup Directory Gulp.task (' Clear ', function () {GULP.SRC (C.outputpath, {read:false}). Pipe (Clean ()); GULP.SRC (C.revpath, {read:false}). Pipe (Clean ()); GULP.SRC ([' Dist ', ' rev '], {read:false}). Pipe (Clean ()); GULP.SRC (Root ('/**/*.*SCC '), {read:false})//. Pipe (Clean ());});
Record your own Gulp packaging script