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

# Function: defineExternalBundleRslibConfig()

> **defineExternalBundleRslibConfig**(`userLibConfig`: [`ExternalBundleLibConfig`](/next/api/packages/lynx-bundle-rslib-config/interfaces/ExternalBundleLibConfig.md), `encodeOptions?`: [`EncodeOptions`](/next/api/packages/lynx-bundle-rslib-config/interfaces/EncodeOptions.md)): `RslibConfig`

Get the rslib config for building Lynx external bundles.

## Parameters

| Parameter       | Type                                                                                                           |
| --------------- | -------------------------------------------------------------------------------------------------------------- |
| `userLibConfig` | [`ExternalBundleLibConfig`](/next/api/packages/lynx-bundle-rslib-config/interfaces/ExternalBundleLibConfig.md) |
| `encodeOptions` | [`EncodeOptions`](/next/api/packages/lynx-bundle-rslib-config/interfaces/EncodeOptions.md)                     |

## Returns

`RslibConfig`

## Examples

If you want to build an external bundle which use in Lynx background thread, you can use the following code:

```js
// rslib.config.js
import { defineExternalBundleRslibConfig } from '@lynx-js/lynx-bundle-rslib-config'
import { LAYERS, pluginReactLynx } from '@lynx-js/react-rsbuild-plugin'

export default defineExternalBundleRslibConfig({
  id: 'utils-lib',
  source: {
    entry: {
      utils: {
        import: './src/utils.ts',
        layer: LAYERS.BACKGROUND,
      }
    }
  },
  plugins: [pluginReactLynx()],
})
```

Then you can use `lynx.loadScript('utils', { bundleName: 'utils-lib-bundle-url' })` in background thread.

If you want to build an external bundle which use in Lynx main thread, you can use the following code:

```js
// rslib.config.js
import { defineExternalBundleRslibConfig } from '@lynx-js/lynx-bundle-rslib-config'
import { LAYERS, pluginReactLynx } from '@lynx-js/react-rsbuild-plugin'

export default defineExternalBundleRslibConfig({
  id: 'utils-lib',
  source: {
    entry: {
      utils: {
        import: './src/utils.ts',
        layer: LAYERS.MAIN_THREAD,
      }
    }
  },
  plugins: [pluginReactLynx()],
})
```

Then you can use `lynx.loadScript('utils', { bundleName: 'utils-lib-bundle-url' })` in main-thread.

If you want to build an external bundle which use both in Lynx main thread and background thread. You don't need to set the layer.

```js
// rslib.config.js
import { defineExternalBundleRslibConfig } from '@lynx-js/lynx-bundle-rslib-config'
import { pluginReactLynx } from '@lynx-js/react-rsbuild-plugin'

export default defineExternalBundleRslibConfig({
  id: 'utils-lib',
  source: {
    entry: {
      utils: './src/utils.ts',
    },
  },
  plugins: [pluginReactLynx()],
})
```

Then you can use `lynx.loadScript('utils', { bundleName: 'utils-lib-bundle-url' })` in background thread and `lynx.loadScript('utils__main-thread', { bundleName: 'utils-lib-bundle-url' })` in main-thread.
