Gulp-clean----Gulp Series (v)

Source: Internet
Author: User

As I said earlier, when the Css,img,js is removed, watch will listen, but it will not delete the corresponding file.

Now implement the clean task and delete the build directory before performing the task.

First configure the JS task, set the delete directory.

On the basis of the series (d) code, expand it.

1. Install Gulp-clean:

NPM Install--save-dev Gulp-clean

2. Locate Gulp->config.js and configure clean:

/*The Gulp command is run by gulpfile.js, so the SRC and build folder paths are as follows (root directory)*/varsrc = './src '; varDest = './build '; Module.exports={less: {all:src+ "/less/**/*.less",//All LessSRC:SRC + "/less/*.less",//Less that needs to be compiledDest:dest + "/css",//Output DirectorySettings: {//compile the configuration required for the less procedure, which can be empty}}, Images: {src:src+ "/img/**/*", Dest:dest+ "/IMG"}, JS: {src:src+ "/js/**/*", Dest:dest+ "/js"}, clean:{src:dest}}

New Clean task in 3.gulp->tasks:

var gulp = require (' Gulp '); var clean = require (' Gulp-clean '); var config = require ('.. /config '). Clean;gulp.task (function() {    return  gulp.src ( CONFIG.SRC)        . Pipe (Clean ());})

4. Also add the clean task to the default task sequence:

Watch out! The following is an error:

Because of this writing, these tasks are synchronous, and it is possible to delete the side compilation edges completely.

Gulp.task (' Default ', [' clean ', ' less ', ' images ', ' js ', ' Watch ']);

So you need to configure an asynchronous, very simple, add a callback:

var gulp = require (' Gulp '); Gulp.task (function() {    Gulp.start (' less ', ' Images ', ' js ', ' Watch ') ;

5. Also add clean in the Deploy task sequence:

var gulp = require (' Gulp '); Gulp.task (function() {    Gulp.start (' less ', ' Imagemin ', ' uglify ') ;

Running Gulp,build at this time will be deleted first.

Look at the official documents in that sentence too.

>>> GitHub Address, please select the Clean branch <<<

Gulp-clean----Gulp Series (v)

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.