Gulp do a simple JS compression

Source: Internet
Author: User

Installation Tools

Global Installation
NPM Install--global Gulp

Dependent installation of the project
--save-dev Gulp
--save-dev Gulp-rename
--save-dev gulp-uglify
--save-dev Gulp-concat

Create the gulpfile.js in the SRC directory you want to compress

varGulp = require (' Gulp '));varRename = require (' Gulp-rename '));varUglify = require (' gulp-uglify '));varConcat = require (' Gulp-concat '));//Create a task called JsminGulp.task (' min ',function(){    returnGULP.SRC (' Src/**/*.js ')//compress all. js files in the SRC directory (* * for subdirectories),. Pipe (Concat (' All.js '). Pipe (Gulp.dest (' src '))//Output New File. Pipe (Uglify ())//Compress Files. Pipe (Rename ({extname: '. Min.js '}))// Renaming. Pipe (Gulp.dest (' src '))//folder to save after performing compression});//set up a task to perform by defaultGulp.task (' Default ', [' min '])

As a result, an uncompressed all.js and a compressed all.min.js are obtained.

Gulp do a simple JS compression

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.