---
title: "grunt配置-clean任务"
author: "小丑鱼0703"
date: "2015-04-27T10:43:10Z"
tags: []
categories: ["Web前端"]
slug: "grunt-clean"
draft: false
lastmod: "2015-04-27T10:53:49Z"
id: 2206315
url: "https://wangjingyi.iteye.com/blog/2206315"
---

grunt-contrib-clean插件-tasks目录下clean.js文件中配置了一个clean任务:

```java

grunt.registerMultiTask('clean', 'Clean files and folders.', function() {
    // Merge task-specific and/or target-specific options with these defaults.
    var options = this.options({
      force: grunt.option('force') === true,
      'no-write': grunt.option('no-write') === true,
    });

    grunt.verbose.writeflags(options, 'Options');

    // Clean specified files / dirs.
    this.filesSrc.forEach(function(filepath) {
      clean(filepath, options);
    });
  });
```


所以在Gruntfile.js中配置任务的时候很简单：

```java

        grunt.initConfig({
           clean : {
                dist : ['/a','/b','/c'],
                server : 'a'
           }
           
        }),

```

这样执行 grunt clean:dist 命令时就可以成功删除 a.b.c 目录下的文件。

<https://www.npmjs.com/package/grunt-contrib-clean>