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

ParameterTypeDescription
userLibConfigExternalBundleLibConfig
encodeOptionsEncodeOptions(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, LAYERS } from '@lynx-js/lynx-bundle-rslib-config'

export default defineExternalBundleRslibConfig({
  id: 'utils-lib',
  source: {
    entry: {
      utils: {
        import: './src/utils.ts',
        layer: LAYERS.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, LAYERS } from '@lynx-js/lynx-bundle-rslib-config'

export default defineExternalBundleRslibConfig({
  id: 'utils-lib',
  source: {
    entry: {
      utils: {
        import: './src/utils.ts',
        layer: LAYERS.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 许可协议进行许可。