删除文件插件
插件包 | @rushstack/heft (内置) |
插件名称 | delete-files-plugin 由 DeleteFilesPlugin.ts 实现 |
插件配置文件 | (无) |
heft.json 选项 | delete-files-options.schema.json |
此插件删除使用各种通配符指定的目录或文件。
何时使用它
通常不需要: 建议使用 Heft 阶段的 cleanFiles
设置删除构建输出文件,因为这确保了与其他功能(例如 --clean
)的正常交互。 delete-files-plugin
通常仅用于阶段间情况,例如删除以细化 copy-files-plugin
操作的结果。
一些注意事项
- 避免使用此任务删除项目文件夹之外的文件。这样做会违反 Rush 的 项目隔离原则.
- 在可能的情况下,避免使用像
**
这样的低效的 glob 运算符,这些运算符会递归遍历目录树。这些磁盘密集型操作会降低构建速度。
package.json 依赖项
无 - 此功能内置于 @rushstack/heft
中。
配置
delete-files-plugin
是一个内置插件,直接从 @rushstack/heft
加载。以下是加载此插件的任务的代码示例
<项目文件夹>/config/heft.json
{
"$schema": "https://developer.microsoft.com/json-schemas/heft/v0/heft.schema.json",
"extends": "@rushstack/heft-web-rig/profiles/library/config/heft.json",
"phasesByName": {
// ("build" is a user-defined name, not a schema field)
"build": {
"tasksByName": {
// ("post-compile" is a user-defined name, not a schema field)
"post-compile": {
// The "post-compile" task should not run until after "typescript" completes
"taskDependencies": ["typescript"],
"taskPlugin": {
"pluginName": "delete-files-plugin",
"pluginPackage": "@rushstack/heft",
// --------------------------------------------------------------
// EXAMPLE OPTIONS FOR delete-files-plugin
"options": {
"deleteOperations": [
{
"sourcePath": ["temp/typings"],
"fileExtensions": [ ".d.ts" ]
}
]
}
// --------------------------------------------------------------
}
}
}
}
}
}
heft.json 插件选项
此注释模板记录了可用选项。在上面的示例中,它将粘贴在 ------
栏之间。
// OPTIONS FOR delete-files-plugin
// JSON Schema: https://developer.microsoft.com/json-schemas/heft/v0/delete-files-options.schema.json
"options": {
/**
* An array of delete operations to be performed by this task.
*/
"deleteOperations": [
/**
* Absolute path to the source file or folder, relative to the project root.
* If "fileExtensions", "excludeGlobs", or "includeGlobs" are specified, then "sourcePath"
* is assumed to be a folder; if it is not a folder, an error will be thrown.
* Settings such as "includeGlobs" and "excludeGlobs" will be resolved relative to this path.
* If no globs or file extensions are specified, the entire folder will be copied.
* If this parameter is not provided, it defaults to the project root.
*/
// "sourcePath": "assets/images",
/**
* If specified, this option recursively scans all folders under "sourcePath" and includes
* any files that match the specified extensions. If "fileExtensions" and "includeGlobs"
* are both specified, their selections are added together.
*/
// "fileExtensions": [ ".png" ],
/**
* A list of glob patterns that select files to be copied. The paths are resolved relative
* to "sourcePath", which must be a folder path. If "fileExtensions" and "includeGlobs"
* are both specified, their selections are added together.
*
* For glob syntax, refer to: https://npmjs.net.cn/package/fast-glob
*/
// "includeGlobs": [],
/**
* A list of glob patterns that exclude files or folders from being copied. The paths are resolved
* relative to "sourcePath", which must be a folder path. These exclusions eliminate items that
* were selected by the "includeGlobs" or "fileExtensions" setting.
*
* For glob syntax, refer to: https://npmjs.net.cn/package/fast-glob
*/
// "excludeGlobs": [ "**/temp" ],
]
}