Skip to content

Instantly share code, notes, and snippets.

@kbshl
Last active October 30, 2017 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kbshl/ee980c2bc103e1e97108 to your computer and use it in GitHub Desktop.
Save kbshl/ee980c2bc103e1e97108 to your computer and use it in GitHub Desktop.
Gulp Receipe: Delete files and folders
/*
* 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