> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# lib.bundle

- **Type:** `boolean`
- **Default:** `true`
- **CLI:** `--bundle` / `--no-bundle`
- **Top-level config:** Supported

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`.

See [bundle / bundleless](/guide/basic/output-structure.md#bundle--bundleless) for more details.

## Set entry

We should specify the entry file for the build.

### bundle: true

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 the entry through the [source.entry](https://rsbuild.rs/config/source/entry) configuration.

**Example:**

```ts title="rslib.config.ts"
export default {
  lib: [
    {
      format: 'cjs',
      bundle: true,
    },
  ],
  source: {
    entry: {
      index: './foo/index.ts',
    },
  },
};
```

### bundle: false

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/**`.

**Example:**

```ts title="rslib.config.ts"
export default {
  lib: [
    {
      format: 'cjs',
      bundle: false,
    },
  ],
  source: {
    entry: {
      index: './foo/**',
    },
  },
};
```

You can also use with an exclamation mark to exclude some files. For example, exclude test files within the `src` folder:

```ts title="rslib.config.ts"
export default {
  lib: [
    {
      format: 'cjs',
      bundle: false,
    },
  ],
  source: {
    entry: {
      index: ['./src/**', '!src/**/*.test.ts'],
    },
  },
};
```

::: note

If [declaration files generation](/config/lib/dts.md) is enabled, remember to set [exclude](https://www.typescriptlang.org/tsconfig/#exclude) field in `tsconfig.json` to avoid generating TypeScript declaration files for the corresponding files.

For example, exclude test files within the `src` folder:

```json
// tsconfig.json
{
  "include": ["src"],
  "exclude": ["src/**/*.test.ts"]
}
```

:::

## Example

For below file structure of source code:

```
.
├── src
│   ├── index.ts
│   ├── foo.ts
│   └── bar.ts
└── package.json
```

### bundle: true

```ts title="rslib.config.ts"
export default defineConfig({
  lib: [
    {
      format: 'cjs',
      bundle: true,
    },
  ],
});
```

When `bundle` is set to `true`, as known as bundle mode, Rslib will bundle the library into a single file.

```diff
  .
+ ├── dist
+ │   └── index.js
  ├── src
  │   ├── index.ts
  │   ├── foo.ts
  │   └── bar.ts
  └── package.json
```

### bundle: false

```ts title="rslib.config.ts"
export default defineConfig({
  lib: [
    {
      format: 'cjs',
      bundle: false,
    },
  ],
  source: {
    entry: {
      index: ['./src/**'],
    },
  },
});
```

When `bundle` is set to `false`, as known as bundleless mode, Rslib will transform the code into multiple files.

```diff
  .
+ ├── dist
+ │   ├── index.js
+ │   ├── foo.js
+ │   └── bar.js
  ├── src
  │   ├── index.ts
  │   ├── foo.ts
  │   └── bar.ts
  └── package.json
```
