Skip to content

Commit

Permalink
feat: support buildStart hook, close #14
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Sep 10, 2021
1 parent 2fe164b commit 73f550a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 2 additions & 0 deletions src/webpack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ export function getWebpackPlugin<UserOptions = {}> (
if (plugin.webpack) {
plugin.webpack(compiler)
}

plugin.buildStart?.()
}
}
}
Expand Down

0 comments on commit 73f550a

Please sign in to comment.