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
29 changes: 28 additions & 1 deletion website/docs/en/config/source/entry.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ When you build for multiple [environments](/config/environments), you can set di

For example, set different entry for `web` and `node` environments:

```js
```ts title="rsbuild.config.ts"
export default {
environments: {
web: {
Expand All @@ -125,3 +125,30 @@ export default {
},
};
```

## Asynchronous setting

If you need to set entry asynchronously, for example, use [glob](https://www.npmjs.com/package/glob) to scan the directory, you can export an async function in `rsbuild.config.ts`:

```ts title="rsbuild.config.ts"
import path from 'node:path';
import { glob } from 'glob';
import { defineConfig } from '@rsbuild/core';

export default defineConfig(async () => {
const entryFiles = await glob('./src/**/main.{ts,tsx,js,jsx}');

const entry = Object.fromEntries(
entryFiles.map((file) => {
const entryName = path.basename(path.dirname(file));
return [entryName, `./${file}`];
}),
);

return {
source: {
entry: entry,
},
};
});
```
29 changes: 28 additions & 1 deletion website/docs/zh/config/source/entry.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default {

比如为 `web` 和 `node` 环境设置不同的 entry:

```js
```ts title="rsbuild.config.ts"
export default {
environments: {
web: {
Expand All @@ -125,3 +125,30 @@ export default {
},
};
```

## 异步设置

如果你需要异步设置 entry,例如使用 [glob](https://www.npmjs.com/package/glob) 来扫描目录,可以在 `rsbuild.config.ts` 中导出一个异步函数:

```ts title="rsbuild.config.ts"
import path from 'node:path';
import { glob } from 'glob';
import { defineConfig } from '@rsbuild/core';

export default defineConfig(async () => {
const entryFiles = await glob('./src/**/main.{ts,tsx,js,jsx}');

const entry = Object.fromEntries(
entryFiles.map((file) => {
const entryName = path.basename(path.dirname(file));
return [entryName, `./${file}`];
}),
);

return {
source: {
entry: entry,
},
};
});
```
Loading