feat: support buildStart hook, close #14

This commit is contained in:
Anthony Fu 2021-09-10 23:53:46 +08:00
parent 2fe164b846
commit 73f550ad25
3 changed files with 7 additions and 2 deletions

View File

@ -19,13 +19,15 @@ Currently supports:
| Hook | Rollup | Vite | Webpack |
| ---- | ------ | ---- | ------- |
| `transformInclude` | ✅ | ✅ | ✅ |
| [`buildStart`](https://rollupjs.org/guide/en/#buildstart) | ✅ | ✅ | ✅ |
| `transformInclude`* | ✅ | ✅ | ✅ |
| [`transform`](https://rollupjs.org/guide/en/#transformers) | ✅ | ✅ | ✅ |
| [`enforce`](https://rollupjs.org/guide/en/#enforce) | ❌* | ✅ | ✅ |
| [`resolveId`](https://rollupjs.org/guide/en/#resolveid) | ✅ | ✅ | ✅ |
| [`load`](https://rollupjs.org/guide/en/#load) | ✅ | ✅ | ✅ |
- *: Rollup does not support using `enforce` to control the order of plugins. Users will need to maintain the order manually.
- *: Webpack's id filter is outside of loader logic; an additional hook is needed for better perf on Webpack. In Rollup and Vite, this hook has been polyfilled to match the behaviors. See for following usage examples.
- **: Rollup does not support using `enforce` to control the order of plugins. Users need to maintain the order manually.
## Usage

View File

@ -16,6 +16,7 @@ export type TransformResult = string | { code: string; map?: SourceMap | null; }
export interface UnpluginOptions {
name: string;
enforce?: 'post' | 'pre' | undefined;
buildStart?: () => 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

@ -137,6 +137,8 @@ export function getWebpackPlugin<UserOptions = {}> (
if (plugin.webpack) {
plugin.webpack(compiler)
}
plugin.buildStart?.()
}
}
}