diff --git a/packages/compat/webpack/src/createCompiler.ts b/packages/compat/webpack/src/createCompiler.ts index 177d736529..0eb93cbb17 100644 --- a/packages/compat/webpack/src/createCompiler.ts +++ b/packages/compat/webpack/src/createCompiler.ts @@ -21,6 +21,7 @@ export async function createCompiler({ logger.debug('create compiler'); await context.hooks.onBeforeCreateCompiler.call({ bundlerConfigs: webpackConfigs as RspackConfig[], + environments: context.environments, }); const { default: webpack } = await import('webpack'); @@ -48,6 +49,7 @@ export async function createCompiler({ await context.hooks.onDevCompileDone.call({ isFirstCompile, stats: stats as Stats, + environments: context.environments, }); } diff --git a/packages/core/src/provider/createCompiler.ts b/packages/core/src/provider/createCompiler.ts index 64a78c57c9..0793634588 100644 --- a/packages/core/src/provider/createCompiler.ts +++ b/packages/core/src/provider/createCompiler.ts @@ -32,6 +32,7 @@ export async function createCompiler({ logger.debug('create compiler'); await context.hooks.onBeforeCreateCompiler.call({ bundlerConfigs: rspackConfigs, + environments: context.environments, }); if (!(await isSatisfyRspackVersion(rspack.rspackVersion))) { @@ -108,6 +109,7 @@ export async function createCompiler({ await context.hooks.onDevCompileDone.call({ isFirstCompile, stats: stats, + environments: context.environments, }); } diff --git a/packages/core/src/server/devServer.ts b/packages/core/src/server/devServer.ts index 6fadae550e..8983c629be 100644 --- a/packages/core/src/server/devServer.ts +++ b/packages/core/src/server/devServer.ts @@ -345,6 +345,7 @@ export async function createDevServer< await options.context.hooks.onAfterStartDevServer.call({ port, routes, + environments: options.context.environments, }); }, onHTTPUpgrade: devMiddlewares.onUpgrade, diff --git a/packages/shared/src/types/hooks.ts b/packages/shared/src/types/hooks.ts index f5f3e32c93..7d36c7f6a0 100644 --- a/packages/shared/src/types/hooks.ts +++ b/packages/shared/src/types/hooks.ts @@ -29,6 +29,7 @@ export type OnCloseDevServerFn = () => MaybePromise; export type OnDevCompileDoneFn = (params: { isFirstCompile: boolean; stats: Stats | MultiStats; + environments: Record; }) => MaybePromise; export type OnBeforeStartDevServerFn = (params: { @@ -45,6 +46,7 @@ export type Routes = Array<{ export type OnAfterStartDevServerFn = (params: { port: number; routes: Routes; + environments: Record; }) => MaybePromise; export type OnAfterStartProdServerFn = (params: { @@ -54,6 +56,7 @@ export type OnAfterStartProdServerFn = (params: { export type OnBeforeCreateCompilerFn = (params: { bundlerConfigs: B extends 'rspack' ? RspackConfig[] : WebpackConfig[]; + environments: Record; }) => MaybePromise; export type OnAfterCreateCompilerFn< diff --git a/website/docs/en/shared/onAfterBuild.mdx b/website/docs/en/shared/onAfterBuild.mdx index 92300f2a56..2b5c77287a 100644 --- a/website/docs/en/shared/onAfterBuild.mdx +++ b/website/docs/en/shared/onAfterBuild.mdx @@ -9,6 +9,7 @@ function OnAfterBuild( callback: (params: { isFirstCompile: boolean; stats?: Stats | MultiStats; + environments: Record; }) => Promise | void, ): void; ``` diff --git a/website/docs/en/shared/onAfterCreateCompiler.mdx b/website/docs/en/shared/onAfterCreateCompiler.mdx index 3a40c06901..03ac78a9e2 100644 --- a/website/docs/en/shared/onAfterCreateCompiler.mdx +++ b/website/docs/en/shared/onAfterCreateCompiler.mdx @@ -7,5 +7,6 @@ You can access the [Compiler instance](https://webpack.js.org/api/node/#compiler ```ts function OnAfterCreateCompiler(callback: (params: { compiler: Compiler | MultiCompiler; + environments: Record; }) => Promise | void;): void; ``` diff --git a/website/docs/en/shared/onAfterStartDevServer.mdx b/website/docs/en/shared/onAfterStartDevServer.mdx index 082b24f5f9..c660f69f60 100644 --- a/website/docs/en/shared/onAfterStartDevServer.mdx +++ b/website/docs/en/shared/onAfterStartDevServer.mdx @@ -9,6 +9,10 @@ type Routes = Array<{ }>; function OnAfterStartDevServer( - callback: (params: { port: number; routes: Routes }) => Promise | void, + callback: (params: { + port: number; + routes: Routes; + environments: Record; + }) => Promise | void, ): void; ``` diff --git a/website/docs/en/shared/onBeforeBuild.mdx b/website/docs/en/shared/onBeforeBuild.mdx index 0d537dccee..611d5bd3bb 100644 --- a/website/docs/en/shared/onBeforeBuild.mdx +++ b/website/docs/en/shared/onBeforeBuild.mdx @@ -8,6 +8,7 @@ You can access the Rspack configuration array through the `bundlerConfigs` param function OnBeforeBuild( callback: (params: { bundlerConfigs?: WebpackConfig[] | RspackConfig[]; + environments: Record; }) => Promise | void, ): void; ``` diff --git a/website/docs/en/shared/onBeforeCreateCompiler.mdx b/website/docs/en/shared/onBeforeCreateCompiler.mdx index 58534a0106..f2bc21a960 100644 --- a/website/docs/en/shared/onBeforeCreateCompiler.mdx +++ b/website/docs/en/shared/onBeforeCreateCompiler.mdx @@ -8,6 +8,7 @@ You can access the Rspack configuration array through the `bundlerConfigs` param function OnBeforeCreateCompiler( callback: (params: { bundlerConfigs: WebpackConfig[] | RspackConfig[]; + environments: Record; }) => Promise | void, ): void; ``` diff --git a/website/docs/en/shared/onBeforeStartDevServer.mdx b/website/docs/en/shared/onBeforeStartDevServer.mdx index 0742eb940f..89794eb233 100644 --- a/website/docs/en/shared/onBeforeStartDevServer.mdx +++ b/website/docs/en/shared/onBeforeStartDevServer.mdx @@ -3,5 +3,9 @@ Called before starting the dev server. - **Type:** ```ts -function OnBeforeStartDevServer(callback: () => Promise | void): void; +function OnBeforeStartDevServer( + callback: (params: { + environments: Record; + }) => Promise | void, +): void; ``` diff --git a/website/docs/en/shared/onDevCompileDone.mdx b/website/docs/en/shared/onDevCompileDone.mdx index d1c9fa9b19..006c1e5fbf 100644 --- a/website/docs/en/shared/onDevCompileDone.mdx +++ b/website/docs/en/shared/onDevCompileDone.mdx @@ -7,6 +7,7 @@ function OnDevCompileDone( callback: (params: { isFirstCompile: boolean; stats: Stats | MultiStats; + environments: Record; }) => Promise | void, ): void; ``` diff --git a/website/docs/zh/shared/onAfterBuild.mdx b/website/docs/zh/shared/onAfterBuild.mdx index 767803839b..e0907e94e6 100644 --- a/website/docs/zh/shared/onAfterBuild.mdx +++ b/website/docs/zh/shared/onAfterBuild.mdx @@ -9,6 +9,7 @@ function OnAfterBuild( callback: (params: { isFirstCompile: boolean; stats?: Stats | MultiStats; + environments: Record; }) => Promise | void, ): void; ``` diff --git a/website/docs/zh/shared/onAfterCreateCompiler.mdx b/website/docs/zh/shared/onAfterCreateCompiler.mdx index 6509d460ac..b875e29850 100644 --- a/website/docs/zh/shared/onAfterCreateCompiler.mdx +++ b/website/docs/zh/shared/onAfterCreateCompiler.mdx @@ -7,5 +7,6 @@ ```ts function OnAfterCreateCompiler(callback: (params: { compiler: Compiler | MultiCompiler; + environments: Record; }) => Promise | void;): void; ``` diff --git a/website/docs/zh/shared/onAfterStartDevServer.mdx b/website/docs/zh/shared/onAfterStartDevServer.mdx index b6f0a85be1..941aa94ae5 100644 --- a/website/docs/zh/shared/onAfterStartDevServer.mdx +++ b/website/docs/zh/shared/onAfterStartDevServer.mdx @@ -9,6 +9,10 @@ type Routes = Array<{ }>; function OnAfterStartDevServer( - callback: (params: { port: number; routes: Routes }) => Promise | void, + callback: (params: { + port: number; + routes: Routes; + environments: Record; + }) => Promise | void, ): void; ``` diff --git a/website/docs/zh/shared/onBeforeBuild.mdx b/website/docs/zh/shared/onBeforeBuild.mdx index c9e0130b2c..0ff5b142c1 100644 --- a/website/docs/zh/shared/onBeforeBuild.mdx +++ b/website/docs/zh/shared/onBeforeBuild.mdx @@ -8,6 +8,7 @@ function OnBeforeBuild( callback: (params: { bundlerConfigs?: WebpackConfig[] | RspackConfig[]; + environments: Record; }) => Promise | void, ): void; ``` diff --git a/website/docs/zh/shared/onBeforeCreateCompiler.mdx b/website/docs/zh/shared/onBeforeCreateCompiler.mdx index df53917b33..ea9430bc6c 100644 --- a/website/docs/zh/shared/onBeforeCreateCompiler.mdx +++ b/website/docs/zh/shared/onBeforeCreateCompiler.mdx @@ -8,6 +8,7 @@ function OnBeforeCreateCompiler( callback: (params: { bundlerConfigs: WebpackConfig[] | RspackConfig[]; + environments: Record; }) => Promise | void, ): void; ``` diff --git a/website/docs/zh/shared/onBeforeStartDevServer.mdx b/website/docs/zh/shared/onBeforeStartDevServer.mdx index f356e6b680..6479c2a53e 100644 --- a/website/docs/zh/shared/onBeforeStartDevServer.mdx +++ b/website/docs/zh/shared/onBeforeStartDevServer.mdx @@ -3,5 +3,9 @@ - **类型:** ```ts -function OnBeforeStartDevServer(callback: () => Promise | void): void; +function OnBeforeStartDevServer( + callback: (params: { + environments: Record; + }) => Promise | void, +): void; ``` diff --git a/website/docs/zh/shared/onDevCompileDone.mdx b/website/docs/zh/shared/onDevCompileDone.mdx index 406d1aa556..ff3a3af9f4 100644 --- a/website/docs/zh/shared/onDevCompileDone.mdx +++ b/website/docs/zh/shared/onDevCompileDone.mdx @@ -7,6 +7,7 @@ function OnDevCompileDone( callback: (params: { isFirstCompile: boolean; stats: Stats | MultiStats; + environments: Record; }) => Promise | void, ): void; ```