Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add environments param into rsbuild api #2768

Merged
merged 1 commit into from
Jul 3, 2024
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
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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we always put environments at the second parameter? To keep consistent

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable, but some hooks don't have a first parameter, which is weird if for consistency...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get, first param is ok

});
},
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;
```
Loading