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/rspeedy/lynx-bundle-rslib-config.defineexternalbundlerslibconfig.md.
Rspeedy logo
Rspeedy
  • English
  • 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.

    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.