Our mobile Web project uses gulp as an automated deployment tool, because mobile device 4G traffic fee is more expensive, generally we do mobile web App project when the official release of the JS code needs to be compressed to save traffic. Including the use of the third-party JS framework, the official release should also use the compressed version. For their own write JS code, because now is a modular development, JS files are more, need to merge into a file, remove log, compression, based on Gulp Pipeline command, to achieve these is still very easy. Some of the code is as follows:
var gulp = require (' gulp '), var gutil = require (' Gulp-util '), var bower = require (' bower '); var concat = require (' Gulp-concat var sass = require (' Gulp-sass '), var minifycss = require (' gulp-minify-css '); var rename = require (' gulp-rename '); var sh = Require (' Shelljs '); var ngmin = require (' gulp-ngmin '); var stripdebug = require (' Gulp-strip-debug ');
Gulp.task (' Minify ', function () { return gulp.src ('./www/js/**/*.js ') . Pipe (Ngmin ({dynamic:false})) . Pipe (Stripdebug ()) . Pipe (Uglify ({outsourcemap:false})). Pipe ( concat (' all.min.js ')) . Pipe (gulp.dest ('./www/js/')});
The required gulp plugin can be downloaded and installed via the NPM Install command after the Package.json file (below) is configured.
{ "name": "Ionic-project", "version": "1.0.0", "description": "An Ionic project", "dependencies": { "Gulp": "^3.5.6", "Gulp-sass": "^0.7.1", "Gulp-concat": "^2.2.0", "gulp-minify-css": "^0.3.0", " Gulp-rename ":" ^1.2.0 " }, " Devdependencies ": { " bower ":" ^1.3.3 ", " Gulp-jshint ":" ^1.9.0 ", "Gulp-ngmin": "^0.3.0", "Gulp-replace": "^0.5.0", "Gulp-rimraf": "^0.1.1", "Gulp-strip-debug ":" ^1.0.2 "," gulp-uglify ":" ^1.0.1 ", " Gulp-util ":" ^2.2.14 ", " Jshint-stylish ":" ^1.0.0 ", " Shelljs ":" ^0.3.0 " }}
Compress and merge Angularjs code with Gulp