1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
# Usage Examples
There are three formats you can use to run this task.
## Short
```js
clean: ['path/to/dir/one', 'path/to/dir/two']
```
## Medium (specific targets with global options)
```js
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)
```js
clean: {
build: {
src: ['path/to/dir/one', 'path/to/dir/two']
}
}
```
"Compact" and "Files Array" formats support a few [additional properties](https://gruntjs.com/configuring-tasks#files)
which help you deal with hidden files, process dynamic mappings and so on.
## Globbing Patterns
Although documented [in the Grunt Docs](https://gruntjs.com/configuring-tasks#globbing-patterns), here are some globbing pattern examples to achieve some common tasks:
```js
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
```js
// 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
```js
// Prevents all targets from deleting any files
clean: {
options: {
'no-write': true
},
build: ['dev/build'],
release: ['dist']
}
```
##### Per-target
```js
// Will delete files for `build` target
// Will NOT delete files for `release` target
clean: {
build: ['dev/build'],
release: {
options: {
'no-write': true
},
src: ['dist']
}
}
```
|