• Stars
    star
    516
  • Rank 82,818 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 11 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Clear files and folders.

grunt-contrib-clean v2.0.1 Build Status

Clean files and folders

Getting Started

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-contrib-clean --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-contrib-clean');

This plugin is designed to work with Grunt 0.4.x and newer. If you're still using grunt v0.3.x it's strongly recommended that you upgrade, but in case you can't please use v0.3.2.

Clean task

Run this task with the grunt clean command.

Task targets, files and options may be specified according to the grunt Configuring tasks guide.

Due to the destructive nature of this task, always be cautious of the paths you clean.

Options

force

Type: Boolean
Default: false

This overrides this task from blocking deletion of folders outside current working dir (CWD). Use with caution.

no-write

Type: Boolean
Default: false

Will not actually delete any files or directories. If the task is run with the --verbose flag, the task will log messages of what files would have be deleted.

Note: As this task property contains a hyphen, you will need to surround it with quotes.

Usage Examples

There are three formats you can use to run this task.

Short

clean: ['path/to/dir/one', 'path/to/dir/two']

Medium (specific targets with global options)

clean: {
  build: ['path/to/dir/one', 'path/to/dir/two'],
  release: ['path/to/another/dir/one', 'path/to/another/dir/two']
},

Long (specific targets with per target options)

clean: {
  build: {
    src: ['path/to/dir/one', 'path/to/dir/two']
  }
}

"Compact" and "Files Array" formats support a few additional properties which help you deal with hidden files, process dynamic mappings and so on.

Globbing Patterns

Although documented in the Grunt Docs, here are some globbing pattern examples to achieve some common tasks:

clean: {
  folder: ['path/to/dir/'],
  folder_v2: ['path/to/dir/**'],
  contents: ['path/to/dir/*'],
  subfolders: ['path/to/dir/*/'],
  css: ['path/to/dir/*.css'],
  all_css: ['path/to/dir/**/*.css']
}
  • folder: Deletes the dir/ folder
  • folder_v2: Deletes the dir/ folder
  • contents: Keeps the dir/ folder, but deletes the contents
  • subfolders: Keeps the files inside the dir/ folder, but deletes all subfolders
  • css: Deletes all *.css files inside the dir/ folder, excluding subfolders
  • all_css: Deletes all *.css files inside the dir/ folder and its subfolders
Skipping Files
// Deletes all .js files, but skips min.js files
clean: {
  js: ['path/to/dir/*.js', '!path/to/dir/*.min.js']
}
Options

Options can be specified for all clean tasks and for each clean:target.

####### All tasks

// Prevents all targets from deleting any files
clean: {
  options: {
    'no-write': true
  },
  build: ['dev/build'],
  release: ['dist']
}

####### Per-target

// Will delete files for `build` target
// Will NOT delete files for `release` target
clean: {
  build: ['dev/build'],
  release: {
    options: {
      'no-write': true
    },
    src: ['dist']
  }
}

Release History

  • 2022-04-15   v2.0.1   Update all dependencies. Requires node.js > 12.
  • 2018-09-08   v2.0.0   Update all dependencies. Drop Node.js < 6 support.
  • 2017-04-12   v1.1.0   Update grunt to 1.0.0. Updates to docs and changelog. Update internal modules.
  • 2016-02-15   v1.0.0   Drop support for Node.js v0.8. Grunt peer dependency tagged >= 0.4.5. Dependency updates.
  • 2015-11-13   v0.7.0   Dependency updates.
  • 2014-07-27   v0.6.0   Less verbose output. README updates.
  • 2013-07-15   v0.5.0   Use rimraf directly, version 2.2.1 to fix issue on Windows. Add no-write option to mimic grunt.file.delete behavior.
  • 2013-04-16   v0.4.1   Check if file exists to avoid trying to delete a non-existent file.
  • 2013-02-15   v0.4.0   First official release for Grunt 0.4.0.
  • 2013-01-18   v0.4.0rc6   Updating grunt/gruntplugin dependencies to rc6. Changing in-development grunt/gruntplugin dependency versions from tilde version ranges to specific versions.
  • 2013-01-09   v0.4.0rc5   Updating to work with grunt v0.4.0rc5. Switching to this.filesSrc API.
  • 2012-12-07   v0.4.0a   Conversion to grunt v0.4 conventions. Remove Node.js v0.6 and grunt v0.3 support. Add force option to bypass CWD check.
  • 2012-09-23   v0.3.0   Options no longer accepted from global config key.
  • 2012-09-10   v0.2.0   Refactored from grunt-contrib into individual repo.

Task submitted by Tim Branyen

This is a generated file.

More Repositories

1

grunt

Grunt: The JavaScript Task Runner
JavaScript
12,255
star
2

grunt-contrib-watch

Run tasks whenever watched files change.
JavaScript
1,981
star
3

grunt-contrib-uglify

Minify files with UglifyJS.
JavaScript
1,481
star
4

grunt-contrib-imagemin

Minify PNG, JPG, GIF and SVG images.
JavaScript
1,214
star
5

grunt-contrib-sass

Compile Sass to CSS.
JavaScript
848
star
6

grunt-contrib-concat

Concatenate files.
JavaScript
809
star
7

grunt-contrib-cssmin

Compress CSS files.
JavaScript
795
star
8

grunt-contrib-copy

Copy files and folders.
JavaScript
729
star
9

grunt-contrib-connect

Start a static web server.
JavaScript
717
star
10

grunt-contrib-jshint

Validate files with JSHint.
JavaScript
710
star
11

grunt-cli

Grunt's command line interface.
JavaScript
708
star
12

grunt-contrib-less

Compile LESS files to CSS.
JavaScript
671
star
13

grunt-contrib-compass

Compile Compass to CSS.
JavaScript
626
star
14

grunt-contrib-requirejs

Optimize RequireJS projects using r.js.
JavaScript
504
star
15

grunt-contrib

[DEPRECATED] A collection of common grunt tasks.
JavaScript
476
star
16

grunt-contrib-htmlmin

Minify HTML.
JavaScript
427
star
17

grunt-contrib-jasmine

Run jasmine specs headlessly through Headless Chrome
JavaScript
356
star
18

grunt-contrib-compress

Compress files and folders.
JavaScript
346
star
19

grunt-contrib-coffee

Compile CoffeeScript files to JavaScript.
JavaScript
330
star
20

grunt-contrib-pug

Compile Pug templates.
JavaScript
329
star
21

grunt-contrib-handlebars

Precompile Handlebars templates to JST file.
JavaScript
282
star
22

grunt-contrib-csslint

Lint CSS files.
JavaScript
242
star
23

grunt-contrib-qunit

Run QUnit tests in Headless Chrome.
JavaScript
215
star
24

grunt-contrib-livereload

Reload assets live in the browser.
JavaScript
203
star
25

grunt-init

Generate project scaffolding from a template.
JavaScript
191
star
26

grunt-contrib-stylus

Compile Stylus files to CSS.
JavaScript
175
star
27

grunt-init-gruntfile

Create a basic Gruntfile with grunt-init.
JavaScript
156
star
28

gruntjs.com

Grunt's Website
Less
156
star
29

grunt-contrib-jst

Compile underscore templates to JST file.
JavaScript
113
star
30

grunt-lib-phantomjs

Grunt and PhantomJS, sitting in a tree.
JavaScript
94
star
31

grunt-next

Grunt v1.0 alpha
JavaScript
84
star
32

grunt-docs

Grunt documentation.
80
star
33

grunt-init-gruntplugin

Create a gruntplugin module with grunt-init, including Nodeunit unit tests.
JavaScript
79
star
34

grunt-contrib-yuidoc

Compile YUIDoc Documentation.
JavaScript
76
star
35

grunt-contrib-nodeunit

Run Nodeunit unit tests.
JavaScript
69
star
36

grunt-contrib-symlink

Create symbolic links.
JavaScript
58
star
37

grunt-init-jquery

Create a jQuery plugin with grunt-init, including QUnit unit tests.
JavaScript
58
star
38

grunt-init-node

Create a Node.js module with grunt-init, including Nodeunit unit tests.
JavaScript
54
star
39

grunt-contrib-bump

A work-in-progress Grunt plugin for bumping a version number in JSON files.
JavaScript
52
star
40

grunt-init-commonjs

Create a commonjs module with grunt-init, including Nodeunit unit tests.
JavaScript
17
star
41

grunt-contrib-internal

Internal tasks for managing the grunt-contrib project.
JavaScript
16
star
42

grunt-init-gruntfile-sample

This is sample output generated by the grunt-init "gruntfile" template.
JavaScript
14
star
43

grunt-init-jquery-sample

This is sample output generated by the grunt-init "jquery" template.
JavaScript
12
star
44

grunt-lib-contrib

Common functionality shared across grunt-contrib tasks.
JavaScript
12
star
45

example-subgrunt

Run a Gruntfile in multiple subdirectories.
JavaScript
11
star
46

grunt-contrib-mincss

Renamed to grunt-contrib-cssmin.
9
star
47

grunt-init-gruntplugin-sample

This is sample output generated by the grunt-init "gruntplugin" template.
JavaScript
9
star
48

grunt-init-node-sample

This is sample output generated by the grunt-init "node" template.
JavaScript
8
star
49

grunt-known-options

The known options used in Grunt
JavaScript
7
star
50

grunt-init-commonjs-sample

This is sample output generated by the grunt-init "commonjs" template.
JavaScript
7
star
51

clone-repos

Quickly clone all gruntjs repos (for grunt development)
Ruby
6
star
52

grunt-lib-legacyhelpers

Some old grunt helpers provided for backwards compatability.
JavaScript
6
star
53

grunt-legacy-util

deprecated utility methods
JavaScript
5
star
54

grunt-legacy-log

The Grunt logger.
JavaScript
5
star
55

rfcs

RFCs for changes to Grunt
4
star
56

grunt-legacy-log-utils

Static methods for the Grunt 0.4.x logger.
JavaScript
4
star
57

grunt-plugin-list

[Deprecated] Generates a list of all grunt plugins as json
JavaScript
4
star
58

grunt-legacy-event-logger

Event logger for Grunt legacy libs.
JavaScript
3
star
59

grunt-legacy-config

Grunt's config methods, as a standalone library.
JavaScript
2
star
60

grunt-legacy-task

Grunt's task methods, as a standalone library.
JavaScript
1
star
61

grunt-legacy-option

Grunt's option methods, as a standalone library.
JavaScript
1
star
62

grunt-legacy-cli

Grunt's CLI methods, as a standalone library.
JavaScript
1
star