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
11 changes: 10 additions & 1 deletion packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ const composeEntryConfig = async (
root: string,
cssModulesAuto: CssLoaderOptionsAuto,
): Promise<{ entryConfig: EnvironmentConfig; lcp: string | null }> => {
let entries = rawEntry;
let entries: RsbuildConfigEntry = rawEntry;

if (!entries) {
// In bundle mode, return directly to let Rsbuild apply default entry to './src/index.ts'
Expand All @@ -904,6 +904,15 @@ const composeEntryConfig = async (
};
}

// Type check to ensure entries is of the expected type
if (typeof entries !== 'object') {
throw new Error(
`The ${color.cyan('source.entry')} configuration should be an object, but received ${typeof entries}: ${color.cyan(
entries,
)}. Checkout ${color.green('https://lib.rsbuild.dev/config/rsbuild/source#sourceentry')} for more details.`,
);
}

if (bundle !== false) {
const entryErrorReasons: string[] = [];
traverseEntryQuery(entries, (entry) => {
Expand Down
13 changes: 13 additions & 0 deletions tests/integration/entry/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,17 @@ test('validate entry and throw errors', async () => {
expect(stripAnsi(errMsg)).toMatchInlineSnapshot(
`"Error: Can't resolve the entry "./src/main.ts" at the location <ROOT>/tests/integration/entry/validate/src/main.ts. Please ensure that the file exists."`,
);

try {
await buildAndGetResults({
fixturePath,
configPath: 'bundlelessWithString.config.ts',
});
} catch (e) {
errMsg = (e as Error).message;
}

expect(stripAnsi(errMsg)).toMatchInlineSnapshot(
`"The source.entry configuration should be an object, but received string: ./src/**. Checkout https://lib.rsbuild.dev/config/rsbuild/source#sourceentry for more details."`,
);
});
14 changes: 14 additions & 0 deletions tests/integration/entry/validate/bundlelessWithString.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineConfig } from '@rslib/core';
import { generateBundleEsmConfig } from 'test-helper';

export default defineConfig({
lib: [
generateBundleEsmConfig({
bundle: false,
source: {
// @ts-expect-error test error config
entry: './src/**',
},
}),
],
});
18 changes: 16 additions & 2 deletions website/docs/en/config/rsbuild/source.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,22 @@ Used to set the entry modules for building.

In Rslib, the default value is:

- bundle mode: `src/index.(ts|js|tsx|jsx|mjs|cjs)`
- bundleless mode: `src/**`
- bundle mode:

```ts
const defaultEntry = {
// default support for other suffixes such as ts, tsx, jsx, mjs, cjs
index: 'src/index.js',
};
```

- bundleless mode:

```ts
const defaultEntry = {
index: 'src/**',
};
```

:::info
Check out the [lib.bundle](/config/lib/bundle#set-entry) to learn more about how to set entry for bundle and bundleless project.
Expand Down
18 changes: 16 additions & 2 deletions website/docs/zh/config/rsbuild/source.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,22 @@ import { RsbuildDocBadge } from '@components/RsbuildDocBadge';

在 Rslib 中,默认值为:

- bundle 模式:`src/index.(ts|js|tsx|jsx|mjs|cjs)`
- bundleless 模式:`src/**`
- bundle 模式:

```ts
const defaultEntry = {
// 默认支持其他后缀,如 ts、tsx、jsx、mjs、cjs
index: 'src/index.js',
};
```

- bundleless 模式:

```ts
const defaultEntry = {
index: 'src/**',
};
```

:::info
参考 [lib.bundle](/config/lib/bundle#set-entry) 进一步了解如何为 bundle 和 bundleless 项目设置入口。
Expand Down
Loading