UNPKG

5.77 kBMarkdownView Raw
1# grunt-contrib-clean v2.0.0 [![Build Status: Linux](https://travis-ci.org/gruntjs/grunt-contrib-clean.svg?branch=master)](https://travis-ci.org/gruntjs/grunt-contrib-clean) [![Build Status: Windows](https://ci.appveyor.com/api/projects/status/li28411ceq3n833d/branch/master?svg=true)](https://ci.appveyor.com/project/gruntjs/grunt-contrib-clean/branch/master)
2
3> Clean files and folders
4
5
6
7## Getting Started
8
9If you haven't used [Grunt](https://gruntjs.com/) before, be sure to check out the [Getting Started](https://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](https://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
10
11```shell
12npm install grunt-contrib-clean --save-dev
13```
14
15Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
16
17```js
18grunt.loadNpmTasks('grunt-contrib-clean');
19```
20
21*This plugin was designed to work with Grunt 0.4.x. If you're still using grunt v0.3.x it's strongly recommended that [you upgrade](https://gruntjs.com/upgrading-from-0.3-to-0.4), but in case you can't please use [v0.3.2](https://github.com/gruntjs/grunt-contrib-clean/tree/grunt-0.3-stable).*
22
23
24
25## Clean task
26_Run this task with the `grunt clean` command._
27
28Task targets, files and options may be specified according to the grunt [Configuring tasks](https://gruntjs.com/configuring-tasks) guide.
29
30*Due to the destructive nature of this task, always be cautious of the paths you clean.*
31### Options
32
33#### force
34Type: `Boolean`
35Default: `false`
36
37This overrides this task from blocking deletion of folders outside current working dir (CWD). Use with caution.
38
39#### no-write
40Type: `Boolean`
41Default: `false`
42
43Will not actually delete any files or directories.
44If the task is run with the `--verbose` flag, the task will log messages of what files would have be deleted.
45
46_Note: As this task property contains a hyphen, you will need to surround it with quotes._
47
48### Usage Examples
49
50There are three formats you can use to run this task.
51
52#### Short
53
54```js
55clean: ['path/to/dir/one', 'path/to/dir/two']
56```
57
58#### Medium (specific targets with global options)
59
60```js
61clean: {
62 build: ['path/to/dir/one', 'path/to/dir/two'],
63 release: ['path/to/another/dir/one', 'path/to/another/dir/two']
64},
65```
66
67#### Long (specific targets with per target options)
68
69```js
70clean: {
71 build: {
72 src: ['path/to/dir/one', 'path/to/dir/two']
73 }
74}
75```
76
77"Compact" and "Files Array" formats support a few [additional properties](https://gruntjs.com/configuring-tasks#files)
78which help you deal with hidden files, process dynamic mappings and so on.
79
80#### Globbing Patterns
81
82Although documented [in the Grunt Docs](https://gruntjs.com/configuring-tasks#globbing-patterns), here are some globbing pattern examples to achieve some common tasks:
83
84```js
85clean: {
86 folder: ['path/to/dir/'],
87 folder_v2: ['path/to/dir/**'],
88 contents: ['path/to/dir/*'],
89 subfolders: ['path/to/dir/*/'],
90 css: ['path/to/dir/*.css'],
91 all_css: ['path/to/dir/**/*.css']
92}
93```
94
95* __`folder`:__ Deletes the `dir/` folder
96* __`folder_v2`:__ Deletes the `dir/` folder
97* __`contents`:__ Keeps the `dir/` folder, but deletes the contents
98* __`subfolders`:__ Keeps the files inside the `dir/` folder, but deletes all subfolders
99* __`css`:__ Deletes all `*.css` files inside the `dir/` folder, excluding subfolders
100* __`all_css`:__ Deletes all `*.css` files inside the `dir/` folder and its subfolders
101
102##### Skipping Files
103
104```js
105// Deletes all .js files, but skips min.js files
106clean: {
107 js: ['path/to/dir/*.js', '!path/to/dir/*.min.js']
108}
109```
110
111###### Options
112
113Options can be specified for all `clean` tasks and for each `clean:target`.
114
115####### All tasks
116
117```js
118// Prevents all targets from deleting any files
119clean: {
120 options: {
121 'no-write': true
122 },
123 build: ['dev/build'],
124 release: ['dist']
125}
126```
127
128####### Per-target
129
130```js
131// Will delete files for `build` target
132// Will NOT delete files for `release` target
133clean: {
134 build: ['dev/build'],
135 release: {
136 options: {
137 'no-write': true
138 },
139 src: ['dist']
140 }
141}
142```
143
144
145## Release History
146
147 * 2018-09-08   v2.0.0   Update all dependencies. Drop Node.js < 6 support.
148 * 2017-04-12   v1.1.0   Update grunt to 1.0.0. Updates to docs and changelog. Update internal modules.
149 * 2016-02-15   v1.0.0   Drop support for Node.js v0.8. Grunt peer dependency tagged `>= 0.4.5`. Dependency updates.
150 * 2015-11-13   v0.7.0   Dependency updates.
151 * 2014-07-27   v0.6.0   Less verbose output. README updates.
152 * 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.
153 * 2013-04-16   v0.4.1   Check if file exists to avoid trying to delete a non-existent file.
154 * 2013-02-15   v0.4.0   First official release for Grunt 0.4.0.
155 * 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.
156 * 2013-01-09   v0.4.0rc5   Updating to work with grunt v0.4.0rc5. Switching to `this.filesSrc` API.
157 * 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.
158 * 2012-09-23   v0.3.0   Options no longer accepted from global config key.
159 * 2012-09-10   v0.2.0   Refactored from grunt-contrib into individual repo.
160
161---
162
163Task submitted by [Tim Branyen](http://tbranyen.com/)
164
165*This file was generated on Sat Sep 08 2018 11:53:35.*