Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion e2e/cases/plugin-api/plugin-hooks-environment/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ const createPlugin = () => {
api.onBeforeEnvironmentCompile(({ environment }) => {
names.push(`BeforeEnvironmentCompile ${environment.name}`);
});
api.onAfterEnvironmentCompile(({ stats, environment }) => {
api.onAfterEnvironmentCompile(({ stats, environment, time }) => {
expect(stats?.compilation.name).toBe(environment.name);
expect(time).toBeGreaterThan(0);
names.push(`AfterEnvironmentCompile ${environment.name}`);
});
api.onBeforeStartProdServer(() => {
Expand Down
20 changes: 14 additions & 6 deletions packages/core/src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,15 +407,19 @@ export const registerBuildHook = ({
await promise;
};

const onEnvironmentDone = async (buildIndex: number, stats: Rspack.Stats) => {
const onEnvironmentDone = async (index: number, stats: Rspack.Stats) => {
const environment = environmentList[index];
const time = context.buildState.time[environment.name] ?? 0;

await context.hooks.onAfterEnvironmentCompile.callBatch({
environment: environmentList[buildIndex].name,
environment: environment.name,
args: [
{
isFirstCompile,
stats,
environment: environmentList[buildIndex],
environment,
isWatch,
time,
},
],
});
Expand Down Expand Up @@ -484,15 +488,19 @@ export const registerDevHook = ({
await promise;
};

const onEnvironmentDone = async (buildIndex: number, stats: Rspack.Stats) => {
const onEnvironmentDone = async (index: number, stats: Rspack.Stats) => {
const environment = environmentList[index];
const time = context.buildState.time[environment.name] ?? 0;

await context.hooks.onAfterEnvironmentCompile.callBatch({
environment: environmentList[buildIndex].name,
environment: environment.name,
args: [
{
isFirstCompile,
stats,
environment: environmentList[buildIndex],
environment,
isWatch: true,
time,
},
],
});
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/types/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export type OnBeforeDevCompileFn<B = 'rspack'> = (
export type OnAfterEnvironmentCompileFn = (
params: CompileCommonParams & {
stats?: Rspack.Stats;
/**
* The time it takes to build the current environment in milliseconds.
*/
time: number;
environment: EnvironmentContext;
},
) => MaybePromise<void>;
Expand Down
4 changes: 4 additions & 0 deletions website/docs/en/shared/onAfterEnvironmentCompile.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ function OnAfterEnvironmentCompile(
isWatch: boolean;
stats?: Stats;
environment: EnvironmentContext;
/**
* The time it takes to build the current environment in milliseconds.
*/
time: number;
}) => Promise<void> | void,
): void;
```
4 changes: 4 additions & 0 deletions website/docs/zh/shared/onAfterEnvironmentCompile.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ function OnAfterEnvironmentCompile(
isWatch: boolean;
stats?: Stats;
environment: EnvironmentContext;
/**
* The time it takes to build the current environment in milliseconds.
*/
time: number;
}) => Promise<void> | void,
): void;
```
Loading