Skip to content

Commit

Permalink
feat: support buildEnd hook, close #27 (#34)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
  • Loading branch information
Zenquan and antfu committed Oct 25, 2021
1 parent 9d0344c commit c95f42d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |\*\* ||||
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
6 changes: 6 additions & 0 deletions src/webpack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ export function getWebpackPlugin<UserOptions = {}> (
}

plugin.buildStart?.()

if (plugin.buildEnd) {
compiler.hooks.done.tapAsync(plugin.name, () => {
plugin.buildEnd!()
})
}
}
}
}
Expand Down

0 comments on commit c95f42d

Please sign in to comment.