|
3 | 3 | - **Type:** `boolean` |
4 | 4 | - **Default:** `true` |
5 | 5 |
|
6 | | -Whether to bundle the library. |
| 6 | +Specify whether to bundle the library, which is known as bundle mode when `bundle` is set to `true`, and bundleless mode when set to `false`. |
| 7 | + |
| 8 | +See [bundle / bundleless](/guide/basic/output-structure#bundle--bundleless) for more details. |
| 9 | + |
| 10 | +::: warning |
| 11 | + |
| 12 | +The bundleless mode is not fully supported yet, and some features like [assets](/guide/advanced/assets) may not work properly. |
| 13 | + |
| 14 | +::: |
| 15 | + |
| 16 | +## Set Entry |
| 17 | + |
| 18 | +We should specify the entry file for the build. |
| 19 | + |
| 20 | +### bundle: true |
| 21 | + |
| 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. |
| 23 | + |
| 24 | +```ts title="rslib.config.ts" |
| 25 | +export default { |
| 26 | + lib: [ |
| 27 | + { |
| 28 | + format: 'cjs', |
| 29 | + bundle: true, |
| 30 | + }, |
| 31 | + ], |
| 32 | + source: { |
| 33 | + entry: { |
| 34 | + index: './foo/index.ts', |
| 35 | + }, |
| 36 | + }, |
| 37 | +}; |
| 38 | +``` |
| 39 | + |
| 40 | +### bundle: false |
| 41 | + |
| 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. |
| 43 | + |
| 44 | +```ts title="rslib.config.ts" |
| 45 | +export default { |
| 46 | + lib: [ |
| 47 | + { |
| 48 | + format: 'cjs', |
| 49 | + bundle: false, |
| 50 | + }, |
| 51 | + ], |
| 52 | + source: { |
| 53 | + entry: { |
| 54 | + index: './src/**', |
| 55 | + }, |
| 56 | + }, |
| 57 | +}; |
| 58 | +``` |
| 59 | + |
| 60 | +You can also use with an exclamation mark to exclude some files. |
| 61 | + |
| 62 | +```ts title="rslib.config.ts" |
| 63 | +export default { |
| 64 | + lib: [ |
| 65 | + { |
| 66 | + format: 'cjs', |
| 67 | + bundle: false, |
| 68 | + }, |
| 69 | + ], |
| 70 | + source: { |
| 71 | + entry: { |
| 72 | + index: ['./src/**', '!**/foo.*'], |
| 73 | + }, |
| 74 | + }, |
| 75 | +}; |
| 76 | +``` |
| 77 | + |
| 78 | +## Example |
| 79 | + |
| 80 | +For below file structure of source code: |
| 81 | + |
| 82 | +``` |
| 83 | +. |
| 84 | +├── src |
| 85 | +│ ├── index.ts |
| 86 | +│ ├── foo.ts |
| 87 | +│ └── bar.ts |
| 88 | +└── package.json |
| 89 | +``` |
| 90 | + |
| 91 | +### bundle: true |
| 92 | + |
| 93 | +```ts title="rslib.config.ts" |
| 94 | +export default defineConfig({ |
| 95 | + lib: [ |
| 96 | + { |
| 97 | + format: 'cjs', |
| 98 | + bundle: true, |
| 99 | + }, |
| 100 | + ], |
| 101 | +}); |
| 102 | +``` |
| 103 | + |
| 104 | +When `bundle` is set to `true`, as known as bundle mode, Rslib will bundle the library into a single file. |
| 105 | + |
| 106 | +```diff |
| 107 | + . |
| 108 | ++ ├── dist |
| 109 | ++ │ └── index.js |
| 110 | + ├── src |
| 111 | + │ ├── index.ts |
| 112 | + │ ├── foo.ts |
| 113 | + │ └── bar.ts |
| 114 | + └── package.json |
| 115 | +``` |
| 116 | + |
| 117 | +### bundle: false |
| 118 | + |
| 119 | +```ts title="rslib.config.ts" |
| 120 | +export default defineConfig({ |
| 121 | + lib: [ |
| 122 | + { |
| 123 | + format: 'cjs', |
| 124 | + bundle: false, |
| 125 | + }, |
| 126 | + ], |
| 127 | + source: { |
| 128 | + entry: { |
| 129 | + index: ['./src/**'], |
| 130 | + }, |
| 131 | + }, |
| 132 | +}); |
| 133 | +``` |
| 134 | + |
| 135 | +When `bundle` is set to `false`, as known as bundleless mode, Rslib will only transform the code into multiple files. |
| 136 | + |
| 137 | +```diff |
| 138 | + . |
| 139 | ++ ├── dist |
| 140 | ++ │ ├── index.js |
| 141 | ++ │ ├── foo.js |
| 142 | ++ │ └── bar.js |
| 143 | + ├── src |
| 144 | + │ ├── index.ts |
| 145 | + │ ├── foo.ts |
| 146 | + │ └── bar.ts |
| 147 | + └── package.json |
| 148 | +``` |
0 commit comments