[grunt] grunt-contrib-clean介绍
发布于 4 年前 作者 qjzd 1993 次浏览 来自 码农

git地址

https://github.com/gruntjs/grunt-contrib-clean

介绍

Clean files and folders 删除文件和目录

Getting Started 入门指南 (翻译ReadMe)

This plugin requires Grunt >=0.4.0

这个插件依赖版本高于0.4.0的Grunt

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:

如果你还没有使用过Grunt, 一定要阅读入门指南, 因为它解释了如何创建一个Gruntfile以及安装和使用Grunt插件。
一旦你熟悉这一过程,你可以安装这个插件使用这个命令:
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:

一旦这个插件已经安装,这可能使在把以下这一行放在Gruntfile中
grunt.loadNpmTasks('grunt-contrib-clean');

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, but in case you can’t please use v0.3.2.

这个插件需要与Grunt0.4.x一起工作。如果你仍然使用版本为0.3.x的Grunt。强烈建议你升级, 但是如果你无法升级到0.4.x还是请使用v0.3.2。

Clean task 删除任务

Run this task with the grunt clean command.

使用grunt clean命令,开始运行该任务

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

grunt的任务 目标, 文件和选项可能需要使用

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 log messages of what would happen if the task was run but doesn’t actually delete the files.

会打印本应该发生的任务的相关信息,实际上不会删除这些文件

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"]
  }
}
clean: {
  options: {
        "no-write": false
  },
  build: {
  	 options: {
        "no-write": false
     },
    src: ["path/to/dir/one", "path/to/dir/two"]
  }
}
Skipping Files (跳过某些问题件)
// Deletes all .js files, but skips min.js files     除了min.js不删外,其他js全部删除
clean: {
  js: ["path/to/dir/*.js", "!path/to/dir/*.min.js"]
}

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

回到顶部