Use gulp to compress and merge AngularJS code
Our mobile web project uses gulp as an automated deployment tool. Because the 4G traffic fee of mobile devices is expensive, js Code is usually compressed when we officially launch the mobile Web App project to save traffic. Including the third-party js framework used. The compressed version should also be used for official release. For self-written js Code, because it is now a modular development, there are many js files, you need to first combine them into a file, remove the log, compress, and use the gulp-Based Pipeline command, it is easy to implement these features. Some 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 plug-in can be configured in the package. json file (as follows), and then downloaded and installed using the npm install command.
{ "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" }}