刪除檔案外掛程式
外掛程式套件 | @rushstack/heft (內建) |
外掛程式名稱 | delete-files-plugin 實作於 DeleteFilesPlugin.ts |
外掛程式設定檔 | (無) |
heft.json 選項 | delete-files-options.schema.json |
此外掛程式使用各種萬用字元,刪除指定檔案或資料夾。
何時使用
通常不需要: 建議使用 cleanFiles
設定,針對 Heft 階段刪除建置輸出檔案,因為這可確保與其他功能(例如 --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://www.npmjs.com/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://www.npmjs.com/package/fast-glob
*/
// "excludeGlobs": [ "**/temp" ],
]
}