Skip to content

Commit

Permalink
feat: add environments param into rsbuild api
Browse files Browse the repository at this point in the history
  • Loading branch information
9aoy committed Jul 3, 2024
1 parent e0a1f8d commit e2bf455
Show file tree
Hide file tree
Showing 18 changed files with 38 additions and 4 deletions.
2 changes: 2 additions & 0 deletions packages/compat/webpack/src/createCompiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -48,6 +49,7 @@ export async function createCompiler({
await context.hooks.onDevCompileDone.call({
isFirstCompile,
stats: stats as Stats,
environments: context.environments,
});
}

Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/provider/createCompiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))) {
Expand Down Expand Up @@ -108,6 +109,7 @@ export async function createCompiler({
await context.hooks.onDevCompileDone.call({
isFirstCompile,
stats: stats,
environments: context.environments,
});
}

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/server/devServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ export async function createDevServer<
await options.context.hooks.onAfterStartDevServer.call({
port,
routes,
environments: options.context.environments,
});
},
onHTTPUpgrade: devMiddlewares.onUpgrade,
Expand Down
3 changes: 3 additions & 0 deletions packages/shared/src/types/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export type OnCloseDevServerFn = () => MaybePromise<void>;
export type OnDevCompileDoneFn = (params: {
isFirstCompile: boolean;
stats: Stats | MultiStats;
environments: Record<string, EnvironmentContext>;
}) => MaybePromise<void>;

export type OnBeforeStartDevServerFn = (params: {
Expand All @@ -45,6 +46,7 @@ export type Routes = Array<{
export type OnAfterStartDevServerFn = (params: {
port: number;
routes: Routes;
environments: Record<string, EnvironmentContext>;
}) => MaybePromise<void>;

export type OnAfterStartProdServerFn = (params: {
Expand All @@ -54,6 +56,7 @@ export type OnAfterStartProdServerFn = (params: {

export type OnBeforeCreateCompilerFn<B = 'rspack'> = (params: {
bundlerConfigs: B extends 'rspack' ? RspackConfig[] : WebpackConfig[];
environments: Record<string, EnvironmentContext>;
}) => MaybePromise<void>;

export type OnAfterCreateCompilerFn<
Expand Down
1 change: 1 addition & 0 deletions website/docs/en/shared/onAfterBuild.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function OnAfterBuild(
callback: (params: {
isFirstCompile: boolean;
stats?: Stats | MultiStats;
environments: Record<string, EnvironmentContext>;
}) => Promise<void> | void,
): void;
```
1 change: 1 addition & 0 deletions website/docs/en/shared/onAfterCreateCompiler.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, EnvironmentContext>;
}) => Promise<void> | void;): void;
```
6 changes: 5 additions & 1 deletion website/docs/en/shared/onAfterStartDevServer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ type Routes = Array<{
}>;

function OnAfterStartDevServer(
callback: (params: { port: number; routes: Routes }) => Promise<void> | void,
callback: (params: {
port: number;
routes: Routes;
environments: Record<string, EnvironmentContext>;
}) => Promise<void> | void,
): void;
```
1 change: 1 addition & 0 deletions website/docs/en/shared/onBeforeBuild.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ You can access the Rspack configuration array through the `bundlerConfigs` param
function OnBeforeBuild(
callback: (params: {
bundlerConfigs?: WebpackConfig[] | RspackConfig[];
environments: Record<string, EnvironmentContext>;
}) => Promise<void> | void,
): void;
```
1 change: 1 addition & 0 deletions website/docs/en/shared/onBeforeCreateCompiler.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ You can access the Rspack configuration array through the `bundlerConfigs` param
function OnBeforeCreateCompiler(
callback: (params: {
bundlerConfigs: WebpackConfig[] | RspackConfig[];
environments: Record<string, EnvironmentContext>;
}) => Promise<void> | void,
): void;
```
6 changes: 5 additions & 1 deletion website/docs/en/shared/onBeforeStartDevServer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@ Called before starting the dev server.
- **Type:**

```ts
function OnBeforeStartDevServer(callback: () => Promise<void> | void): void;
function OnBeforeStartDevServer(
callback: (params: {
environments: Record<string, EnvironmentContext>;
}) => Promise<void> | void,
): void;
```
1 change: 1 addition & 0 deletions website/docs/en/shared/onDevCompileDone.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ function OnDevCompileDone(
callback: (params: {
isFirstCompile: boolean;
stats: Stats | MultiStats;
environments: Record<string, EnvironmentContext>;
}) => Promise<void> | void,
): void;
```
1 change: 1 addition & 0 deletions website/docs/zh/shared/onAfterBuild.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function OnAfterBuild(
callback: (params: {
isFirstCompile: boolean;
stats?: Stats | MultiStats;
environments: Record<string, EnvironmentContext>;
}) => Promise<void> | void,
): void;
```
1 change: 1 addition & 0 deletions website/docs/zh/shared/onAfterCreateCompiler.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
```ts
function OnAfterCreateCompiler(callback: (params: {
compiler: Compiler | MultiCompiler;
environments: Record<string, EnvironmentContext>;
}) => Promise<void> | void;): void;
```
6 changes: 5 additions & 1 deletion website/docs/zh/shared/onAfterStartDevServer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ type Routes = Array<{
}>;

function OnAfterStartDevServer(
callback: (params: { port: number; routes: Routes }) => Promise<void> | void,
callback: (params: {
port: number;
routes: Routes;
environments: Record<string, EnvironmentContext>;
}) => Promise<void> | void,
): void;
```
1 change: 1 addition & 0 deletions website/docs/zh/shared/onBeforeBuild.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
function OnBeforeBuild(
callback: (params: {
bundlerConfigs?: WebpackConfig[] | RspackConfig[];
environments: Record<string, EnvironmentContext>;
}) => Promise<void> | void,
): void;
```
1 change: 1 addition & 0 deletions website/docs/zh/shared/onBeforeCreateCompiler.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
function OnBeforeCreateCompiler(
callback: (params: {
bundlerConfigs: WebpackConfig[] | RspackConfig[];
environments: Record<string, EnvironmentContext>;
}) => Promise<void> | void,
): void;
```
6 changes: 5 additions & 1 deletion website/docs/zh/shared/onBeforeStartDevServer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
- **类型:**

```ts
function OnBeforeStartDevServer(callback: () => Promise<void> | void): void;
function OnBeforeStartDevServer(
callback: (params: {
environments: Record<string, EnvironmentContext>;
}) => Promise<void> | void,
): void;
```
1 change: 1 addition & 0 deletions website/docs/zh/shared/onDevCompileDone.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ function OnDevCompileDone(
callback: (params: {
isFirstCompile: boolean;
stats: Stats | MultiStats;
environments: Record<string, EnvironmentContext>;
}) => Promise<void> | void,
): void;
```

0 comments on commit e2bf455

Please sign in to comment.