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

# lib.autoExternal

:::warning
`lib.autoExternal` is deprecated. Please use [output.autoExternal](/config/rsbuild/output.md#outputautoexternal) instead.
:::

:::info

`autoExternal` is a specific configuration for bundle mode. It will not take effect in bundleless mode (set [lib.bundle](/config/lib/bundle.md) to `false`) since deps will not be bundled in bundleless mode.

:::

- **Type:**

```ts
type AutoExternal =
  | boolean
  | {
      dependencies?: boolean;
      optionalDependencies?: boolean;
      devDependencies?: boolean;
      peerDependencies?: boolean;
    };
```

- **Default:**
  - `true` when [format](/config/lib/format.md) is `cjs` or `esm`
  - `false` when [format](/config/lib/format.md) is `umd` or `mf`
- **CLI:** `--auto-external` / `--no-auto-external`

Whether to automatically externalize dependencies of different dependency types and do not bundle them.

## Object type

### autoExternal.dependencies

- **Type:** `boolean`
- **Default:** `true`

Whether to automatically externalize dependencies of type `dependencies`.

### autoExternal.optionalDependencies

- **Type:** `boolean`
- **Default:** `true`

Whether to automatically externalize dependencies of type `optionalDependencies`.

### autoExternal.peerDependencies

- **Type:** `boolean`
- **Default:** `true`

Whether to automatically externalize dependencies of type `peerDependencies`.

### autoExternal.devDependencies

- **Type:** `boolean`
- **Default:** `false`

Whether to automatically externalize dependencies of type `devDependencies`.

## Default value

The default value of `autoExternal` is `true`, which means the following dependency types will **not be bundled**:

- `dependencies`
- `optionalDependencies`
- `peerDependencies`

And the following dependency types will be **bundled**:

- `devDependencies`

This configuration is equivalent to the following object type:

```ts
export default {
  lib: [
    {
      format: 'esm',
      autoExternal: {
        dependencies: true,
        optionalDependencies: true,
        peerDependencies: true,
        devDependencies: false,
      },
    },
  ],
};
```

## Example

### Customize externalized dependency types

To disable the processing of a specific type of dependency, you can configure `autoExternal` as an object like this:

```ts title="rslib.config.ts"
export default {
  lib: [
    {
      format: 'esm',
      autoExternal: {
        dependencies: false,
        peerDependencies: false,
      },
    },
  ],
};
```

### Disable default behavior

If you want to disable the default behavior, you can set `autoExternal` to `false`:

```ts title="rslib.config.ts"
export default {
  lib: [
    {
      format: 'esm',
      autoExternal: false,
    },
  ],
};
```

For more details about handling third-party dependencies, please refer to [Handle Third-party Dependencies](/guide/advanced/third-party-deps.md).
