import type { LibConfig, RslibConfig } from '@rslib/core'; /** * The options for encoding the external bundle. * * @public */ export interface EncodeOptions { /** * The engine version of the external bundle. * * @defaultValue '3.5' */ engineVersion?: string; /** * The output format of the encoded bundle. * * - `'tasm'`: the native TASM bundle via `@lynx-js/tasm`. * - `'web'`: a web binary bundle via `@lynx-js/web-core/encode`, decodable by * the web platform. Sections are emitted as raw JS (the web runtime wraps * them at `lynx.loadScript` time), and CSS is folded into the StyleInfo * section. * * @defaultValue 'tasm' */ target?: 'web' | 'tasm'; /** * Whether to compile main thread chunks to JsBytecode in the emitted bundle. * * @remarks * When disabled, main thread chunks are encoded as plain JavaScript source, * which keeps them readable for debugging and speeds up encoding. * * Only takes effect for the `'tasm'` target. For the `'web'` target the * `JsBytecode` tag only routes main thread chunks to the correct bundle * slot (the chunk is never bytecode-compiled), so it is always kept. * * @defaultValue `false` when `NODE_ENV` is `'development'`, otherwise `true` */ enableJsBytecode?: boolean; } /** * The default lib config{@link LibConfig} for external bundle. * * @public */ export declare const DEFAULT_EXTERNAL_BUNDLE_LIB_CONFIG: LibConfig; /** * Object form of an external mapping. * * Use this instead of the plain global-name form when the external library is * mounted asynchronously (as a Promise) by the consuming application, i.e. the * matching `pluginExternalBundle` external is configured with `async: true`. * * @public */ export interface ExternalObject { /** * The global name (with optional subpath) of the external library. */ libraryName: string | string[]; /** * Whether the library is mounted as a Promise resolving to the library * namespace. When enabled, the external is emitted as a `promise` external * so importing modules await the mounted value instead of reading it * synchronously. * * @defaultValue false */ async?: boolean; } /** * External module to global-name mappings used when building Lynx external * bundles. * * @public */ export type Externals = Record; /** * Standard ReactLynx external mappings used by the built-in `reactlynx` * preset. * * @public */ export declare const reactLynxExternalsPreset: Externals; /** * How an externals preset is enabled. * * `true` mounts the preset's libraries synchronously. The `{ async: true }` * object form mounts them asynchronously (as Promises), for the web target * where external bundles are loaded via `fetchBundle().then` — see * {@link ExternalObject.async}. * * @public */ export type ExternalsPresetValue = boolean | { async?: boolean; }; /** * Enabled externals presets. * * Preset names are resolved from the built-in preset definitions plus any * custom definitions passed to {@link defineExternalBundleRslibConfig}. * * @public */ export type ExternalsPresets = { reactlynx?: ExternalsPresetValue; } & Record; /** * Definition for a named externals preset. * * @public */ export interface ExternalsPresetDefinition { /** * Other preset names to include before applying the current preset. */ extends?: string | string[]; /** * Externals contributed by this preset. */ externals?: Externals; } /** * Available externals preset definitions. * * @public */ export type ExternalsPresetDefinitions = Record; /** * Built-in externals preset definitions. * * @public */ export declare const builtInExternalsPresetDefinitions: ExternalsPresetDefinitions; /** * Output config accepted by Lynx external bundle builds. * * @public */ export type OutputConfig = Required['output'] & { /** * Presets for external libraries. * * Same as https://rspack.rs/config/externals#externalspresets but for Lynx. */ externalsPresets?: ExternalsPresets; /** * Definitions for custom externals presets enabled by `externalsPresets`. * * Use this to add business-specific presets such as `@lynx-js/lynx-ui`, or to extend a * built-in preset through `extends`. */ externalsPresetDefinitions?: ExternalsPresetDefinitions; externals?: Externals; /** * This option indicates what global object will be used to mount the library. * * In Lynx, the library will be mounted to `lynx[Symbol.for("__LYNX_EXTERNAL_GLOBAL__")]` by default. * * If you have enabled share js context and want to reuse the library by mounting to the global object, you can set this option to `'globalThis'`. * * @defaultValue `'lynx'` */ globalObject?: 'lynx' | 'globalThis'; }; /** * Rslib config shape accepted by `defineExternalBundleRslibConfig`. * * @public */ export interface ExternalBundleLibConfig extends LibConfig { output?: OutputConfig; } /** * Get the rslib config for building Lynx external bundles. * * @public * * @example * * 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' * * 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 * * 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' * * 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 * * 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' * * 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. */ export declare function defineExternalBundleRslibConfig(userLibConfig: ExternalBundleLibConfig, encodeOptions?: EncodeOptions): RslibConfig;