Use gulp to compress and merge AngularJS code

Source: Internet
Author: User

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"  }}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.