diff --git a/website/docs/en/config/lib/auto-external.mdx b/website/docs/en/config/lib/auto-external.mdx index 15f6b94c2..a977304ab 100644 --- a/website/docs/en/config/lib/auto-external.mdx +++ b/website/docs/en/config/lib/auto-external.mdx @@ -1,6 +1,113 @@ # lib.autoExternal -- **Type:** `boolean` +- **Type:** + +```ts +type AutoExternal = + | boolean + | { + dependencies?: boolean; + optionalDependencies?: boolean; + devDependencies?: boolean; + peerDependencies?: boolean; + }; +``` + - **Default:** `true` Whether to automatically externalize dependencies and do not bundle them. + +## autoExternal.dependencies + +- **Type:** `boolean` +- **Default:** `true` + +Whether to externalize dependencies of type `dependencies`. + +## autoExternal.optionalDependencies + +- **Type:** `boolean` +- **Default:** `true` + +Whether to externalize dependencies of type `optionalDependencies`. + +## autoExternal.peerDependencies + +- **Type:** `boolean` +- **Default:** `true` + +Whether to externalize dependencies of type `peerDependencies`. + +## autoExternal.devDependencies + +- **Type:** `boolean` +- **Default:** `false` + +Whether to bundle 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` + +It is equivalent to the following configuration: + +```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). diff --git a/website/docs/en/guide/advanced/third-party-deps.mdx b/website/docs/en/guide/advanced/third-party-deps.mdx index 3c1edaaa5..814598828 100644 --- a/website/docs/en/guide/advanced/third-party-deps.mdx +++ b/website/docs/en/guide/advanced/third-party-deps.mdx @@ -53,7 +53,7 @@ console.info(__WEBPACK_EXTERNAL_MODULE_react__['default']); If you want to modify the default processing, you can use the following API. -- [`lib.autoExternal`](/config/lib/auto-external) +- [lib.autoExternal](/config/lib/auto-external) ## Exclude specified third-party dependencies