For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt, and this page is available as Markdown at /next/api/packages/lynx-bundle-rslib-config/functions/defineExternalBundleRslibConfig.md.
Lynx
  • English
  • Function: defineExternalBundleRslibConfig()

    defineExternalBundleRslibConfig(userLibConfig: ExternalBundleLibConfig, encodeOptions?: EncodeOptions): RslibConfig

    Get the rslib config for building Lynx external bundles.

    Parameters

    ParameterType
    userLibConfigExternalBundleLibConfig
    encodeOptionsEncodeOptions

    Returns

    RslibConfig

    Examples

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

    // 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:

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

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

    Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.