Skip to content

Commit 712608e

Browse files
committed
feat: entry default to src/** in bundleless mode
1 parent 60f4f93 commit 712608e

File tree

11 files changed

+110
-13
lines changed

11 files changed

+110
-13
lines changed

packages/core/src/config.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -879,13 +879,23 @@ export const appendEntryQuery = (entries: RsbuildConfigEntry): RsbuildEntry =>
879879
traverseEntryQuery(entries, (item) => `${item}?${RSLIB_ENTRY_QUERY}`);
880880

881881
const composeEntryConfig = async (
882-
entries: RsbuildConfigEntry,
882+
rawEntry: RsbuildConfigEntry,
883883
bundle: LibConfig['bundle'],
884884
root: string,
885885
cssModulesAuto: CssLoaderOptionsAuto,
886886
): Promise<{ entryConfig: EnvironmentConfig; lcp: string | null }> => {
887+
let entries = rawEntry;
888+
887889
if (!entries) {
888-
return { entryConfig: {}, lcp: null };
890+
// In bundle mode, return directly to let Rsbuild apply default entry to './src/index.ts'
891+
if (bundle !== false) {
892+
return { entryConfig: {}, lcp: null };
893+
}
894+
895+
// In bundleless mode, set default entry to './src/**'
896+
entries = {
897+
index: 'src/**',
898+
};
889899
}
890900

891901
if (bundle !== false) {

pnpm-lock.yaml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "entry-default-test",
3+
"version": "1.0.0",
4+
"private": true,
5+
"type": "module"
6+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { defineConfig } from '@rslib/core';
2+
import { generateBundleCjsConfig, generateBundleEsmConfig } from 'test-helper';
3+
4+
export default defineConfig({
5+
lib: [
6+
generateBundleEsmConfig({
7+
output: {
8+
distPath: {
9+
root: 'dist/esm-bundle',
10+
},
11+
},
12+
}),
13+
generateBundleCjsConfig({
14+
output: {
15+
distPath: {
16+
root: 'dist/cjs-bundle',
17+
},
18+
},
19+
}),
20+
generateBundleEsmConfig({
21+
output: {
22+
distPath: {
23+
root: 'dist/esm-bundle-false',
24+
},
25+
},
26+
bundle: false,
27+
}),
28+
generateBundleCjsConfig({
29+
output: {
30+
distPath: {
31+
root: 'dist/cjs-bundle-false',
32+
},
33+
},
34+
bundle: false,
35+
}),
36+
],
37+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const foo = 'foo';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { foo } from './foo';
2+
3+
export const text = () => `hello ${foo}`;

tests/integration/entry/index.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,30 @@ import stripAnsi from 'strip-ansi';
33
import { buildAndGetResults, queryContent } from 'test-helper';
44
import { expect, test } from 'vitest';
55

6+
test('default entry', async () => {
7+
const fixturePath = join(__dirname, 'default');
8+
const { files } = await buildAndGetResults({ fixturePath });
9+
10+
expect(files).toMatchInlineSnapshot(`
11+
{
12+
"cjs0": [
13+
"<ROOT>/tests/integration/entry/default/dist/cjs-bundle/index.cjs",
14+
],
15+
"cjs1": [
16+
"<ROOT>/tests/integration/entry/default/dist/cjs-bundle-false/foo.cjs",
17+
"<ROOT>/tests/integration/entry/default/dist/cjs-bundle-false/index.cjs",
18+
],
19+
"esm0": [
20+
"<ROOT>/tests/integration/entry/default/dist/esm-bundle/index.js",
21+
],
22+
"esm1": [
23+
"<ROOT>/tests/integration/entry/default/dist/esm-bundle-false/foo.js",
24+
"<ROOT>/tests/integration/entry/default/dist/esm-bundle-false/index.js",
25+
],
26+
}
27+
`);
28+
});
29+
630
test('single entry bundle', async () => {
731
const fixturePath = join(__dirname, 'single');
832
const { files } = await buildAndGetResults({ fixturePath });

website/docs/en/config/lib/bundle.mdx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ We should specify the entry file for the build.
1919

2020
### bundle: true
2121

22-
When `bundle` is set to `true`, the entry should be set to the entry file. The default entry is `src/index.(ts|js|tsx|jsx|mjs|cjs)`. You should make sure that the entry file exists, or customize entry through the [source.entry](https://rsbuild.dev/config/source/entry) configuration.
22+
When `bundle` is set to `true`, the entry should be set to the entry file. The default entry in bundle mode is `src/index.(ts|js|tsx|jsx|mjs|cjs)`. You should make sure that the entry file exists, or customize entry through the [source.entry](https://rsbuild.dev/config/source/entry) configuration.
23+
24+
**Example:**
2325

2426
```ts title="rslib.config.ts"
2527
export default {
@@ -39,7 +41,9 @@ export default {
3941

4042
### bundle: false
4143

42-
When `bundle` is set to `false`, the entry should be set a [glob pattern](https://github.com/micromatch/picomatch#globbing-features) to include all the files.
44+
When `bundle` is set to `false`, the entry should be set to a [glob pattern](https://github.com/micromatch/picomatch#globbing-features) to include all the files. The default entry in bundleless mode is `src/**`.
45+
46+
**Example:**
4347

4448
```ts title="rslib.config.ts"
4549
export default {
@@ -51,7 +55,7 @@ export default {
5155
],
5256
source: {
5357
entry: {
54-
index: './src/**',
58+
index: './foo/**',
5559
},
5660
},
5761
};

website/docs/en/config/rsbuild/source.mdx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ Replaces variables in your code with other values or expressions at compile time
1919

2020
## source.entry <RsbuildDocBadge path="/config/source/entry" text="source.entry" />
2121

22-
Used to set the entry modules for building.
22+
Used to set the entry modules for building. In Rslib, the default value of `source.entry` is:
23+
24+
- bundle mode: `src/index.(ts|js|tsx|jsx|mjs|cjs)`
25+
- bundleless mode: `src/**`
2326

2427
:::info
25-
Check out the [lib.bundle](/config/lib/bundle#set-entry) to learn how to set entry for bundle and bundleless project.
28+
Check out the [lib.bundle](/config/lib/bundle#set-entry) to learn more about how to set entry for bundle and bundleless project.
2629
:::
2730

2831
## source.exclude <RsbuildDocBadge path="/config/source/exclude" text="source.exclude" />

website/docs/zh/config/lib/bundle.mdx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
指定是否打包库,当 `bundle` 设置为 `true` 时称为 bundle 模式,设置为 `false` 时称为 bundleless 模式。更多详情请参见 [bundle / bundleless](/guide/basic/output-structure#bundle--bundleless)
77

88
::: warning
9-
无打包模式尚未完全支持,某些功能如 [资源](/guide/advanced/assets) 可能无法正常工作。
9+
Bundleless 模式尚未完全支持,某些功能如 [资源](/guide/advanced/assets) 可能无法正常工作。
1010
:::
1111

1212
## 设置入口
@@ -15,7 +15,9 @@
1515

1616
### bundle: true
1717

18-
`bundle` 设置为 `true` 时,入口需要设置为入口文件。默认入口为 `src/index.(ts|js|tsx|jsx|mjs|cjs)`。你需要确保入口文件存在,或通过 [source.entry](https://rsbuild.dev/zh/config/source/entry) 配置自定义入口。
18+
`bundle` 设置为 `true` 时,entry 需要设置为入口文件。Bundle 模式下的默认入口为 `src/index.(ts|js|tsx|jsx|mjs|cjs)`。你需要确保入口文件存在,或通过 [source.entry](https://rsbuild.dev/zh/config/source/entry) 配置自定义入口。
19+
20+
**例子:**
1921

2022
```ts title="rslib.config.ts"
2123
export default {
@@ -35,7 +37,9 @@ export default {
3537

3638
### bundle: false
3739

38-
`bundle` 设置为 `false` 时,入口需要设置为 [glob 模式](https://github.com/micromatch/picomatch#globbing-features) 以包含所有文件。
40+
`bundle` 设置为 `false` 时,入口需要设置为 [glob 模式](https://github.com/micromatch/picomatch#globbing-features) 以包含所有文件。Bundleless 模式下的默认入口为 `src/**`
41+
42+
**例子:**
3943

4044
```ts title="rslib.config.ts"
4145
export default {
@@ -47,7 +51,7 @@ export default {
4751
],
4852
source: {
4953
entry: {
50-
index: './src/**',
54+
index: './foo/**',
5155
},
5256
},
5357
};

website/docs/zh/config/rsbuild/source.mdx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ import { RsbuildDocBadge } from '@components/RsbuildDocBadge';
1818

1919
## source.entry <RsbuildDocBadge path="/config/source/entry" text="source.entry" />
2020

21-
用于设置构建的入口模块。
21+
用于设置构建的入口模块。在 Rslib 中,`source.entry` 的默认值为:
22+
23+
- bundle 模式:`src/index.(ts|js|tsx|jsx|mjs|cjs)`
24+
- bundleless 模式:`src/**`
2225

2326
:::info
24-
参考 [lib.bundle](/config/lib/bundle#set-entry) 了解如何为 bundle 和 bundleless 项目设置入口。
27+
参考 [lib.bundle](/config/lib/bundle#set-entry) 进一步了解如何为 bundle 和 bundleless 项目设置入口。
2528
:::
2629

2730
## source.exclude <RsbuildDocBadge path="/config/source/exclude" text="source.exclude" />

0 commit comments

Comments
 (0)