feat: support buildEnd hook, close #27 (#34)

Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
This commit is contained in:
Zenquan 2021-10-25 21:09:48 +08:00 committed by GitHub
parent 9d0344cd6e
commit c95f42dfe9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 0 deletions

View File

@ -20,6 +20,7 @@ Currently supports:
| Hook | Rollup | Vite | Webpack 4 | Webpack 5 |
| ---- | :----: | :--: | :-------: | :-------: |
| [`buildStart`](https://rollupjs.org/guide/en/#buildstart) | ✅ | ✅ | ✅ | ✅ |
| [`buildEnd`](https://rollupjs.org/guide/en/#buildend) | ✅ | ✅ | ✅ | ✅ |
| `transformInclude`* | ✅ | ✅ | ✅ | ✅ |
| [`transform`](https://rollupjs.org/guide/en/#transformers) | ✅ | ✅ | ✅ | ✅ |
| [`enforce`](https://rollupjs.org/guide/en/#enforce) | ❌\*\* | ✅ | ✅ | ✅ |

View File

@ -19,6 +19,7 @@ export interface UnpluginOptions {
name: string;
enforce?: 'post' | 'pre' | undefined;
buildStart?: () => Promise<void> | void;
buildEnd?: () => Promise<void> | void;
transformInclude?: (id: string) => boolean;
transform?: (this: UnpluginContext, code: string, id: string) => Thenable<TransformResult>;
load?: (this: UnpluginContext, id: string) => Thenable<TransformResult>

View File

@ -158,6 +158,12 @@ export function getWebpackPlugin<UserOptions = {}> (
}
plugin.buildStart?.()
if (plugin.buildEnd) {
compiler.hooks.done.tapAsync(plugin.name, () => {
plugin.buildEnd!()
})
}
}
}
}