Last active
October 30, 2017 18:36
-
-
Save kbshl/ee980c2bc103e1e97108 to your computer and use it in GitHub Desktop.
Gulp Receipe: Delete files and folders
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Delete files and folders | |
* You might want delete some files before running your build. Since deleting files doesn't work on the file contents there's no reason to use a gulp plugin. An excellent opportunity to use a vanilla node module. | |
* | |
* Let's use the del module for this example as it supports multiple files and globbing: | |
*/ | |
// $ npm install --save-dev gulp del | |
// Imagine this file structure: | |
/* | |
. | |
├── dist | |
│ ├── report.csv | |
│ ├── desktop | |
│ └── mobile | |
│ ├── app.js | |
│ ├── deploy.json | |
│ └── index.html | |
└── src | |
*/ | |
// In the gulpfile we want to clean out the contents of the mobile folder before running our build: | |
var gulp = require('gulp'); | |
var del = require('del'); | |
gulp.task('clean:mobile', function (cb) { | |
del([ | |
'dist/report.csv', | |
// here we use a globbing pattern to match everything inside the `mobile` folder | |
'dist/mobile/**', | |
// we don't want to clean this file though so we negate the pattern | |
'!dist/mobile/deploy.json' | |
], cb); | |
}); | |
gulp.task('default', ['clean:mobile']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment