For AI agents: the complete documentation index is available at /next/zh/llms.txt, the full documentation bundle is available at /next/zh/llms-full.txt, and this page is available as Markdown at /next/zh/api/rspeedy/lynx-bundle-rslib-config.defineexternalbundlerslibconfig.md.
Rspeedy logo
Rspeedy
  • 简体中文
  • Home > @lynx-js/lynx-bundle-rslib-config > defineExternalBundleRslibConfig

    defineExternalBundleRslibConfig() function

    Get the rslib config for building Lynx external bundles.

    Signature:

    export declare function defineExternalBundleRslibConfig(userLibConfig: ExternalBundleLibConfig, encodeOptions?: EncodeOptions): RslibConfig;

    Parameters

    Parameter

    Type

    Description

    userLibConfig

    ExternalBundleLibConfig

    encodeOptions

    EncodeOptions

    (Optional)

    Returns:

    RslibConfig

    Example 1

    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'
    
    export default defineExternalBundleRslibConfig({
      id: 'utils-lib',
      source: {
        entry: {
          utils: {
            import: './src/utils.ts',
            layer: 'background',
          }
        }
      }
    })

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

    Example 2

    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'
    
    export default defineExternalBundleRslibConfig({
      id: 'utils-lib',
      source: {
        entry: {
          utils: {
            import: './src/utils.ts',
            layer: 'main-thread',
          }
        }
      }
    })

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

    Example 3

    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'
    
    export default defineExternalBundleRslibConfig({
      id: 'utils-lib',
      source: {
        entry: {
          utils: './src/utils.ts',
        },
      }
    })

    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.

    除非另有说明,本项目采用知识共享署名 4.0 国际许可协议进行许可,代码示例采用 Apache License 2.0 许可协议进行许可。