For AI agents: the complete documentation index is available at /zh/llms.txt, the full documentation bundle is available at /zh/llms-full.txt, and this page is available as Markdown at /zh/api/externals-loading-webpack-plugin.externalvalue.md.
这是开发预览网站。请访问正式文档 lynx-stack.dev

Home > @lynx-js/externals-loading-webpack-plugin > ExternalValue

ExternalValue interface

The value item of the externals.

Signature:

export interface ExternalValue 

Properties

Property

Modifiers

Type

Description

async?

boolean | ((context: { systemInfo: Record<string, unknown>; }) => boolean)

(Optional) Whether the source should be loaded asynchronously.

A callback is serialized into the bundle and evaluated at runtime withSystemInfo (falling back to lynx.SystemInfo). It must be a standalone arrow or function expression without closures, and must return a boolean synchronously. Callback externals always use promise module semantics, including when the callback selects synchronous loading.

background?

LayerOptions

(Optional) The options of the background layer.

bundlePath?

string

(Optional) The bundle path resolved against the runtime public path.

Prefer this over url when the bundle should follow the activepublicPath. The runtime will load it with publicPath + bundlePath, which keeps external bundle resolution aligned with the current build output without hard-coding an absolute URL into the generated runtime code.

libraryName?

string | string[]

(Optional) The name of the library. Same as https://webpack.js.org/configuration/externals/\#string.

By default, the library name is the same as the externals key. For example:

The config

ExternalsLoadingPlugin({
  externals: {
    lodash: {
      url: '……',
    }
  }
})

Will generate the following webpack externals config:

externals: {
  lodash: 'lynx[Symbol.for("__LYNX_EXTERNAL_GLOBAL__")].lodash',
}

If one external bundle contains multiple modules, should set the same library name to ensure it's loaded only once. For example:

ExternalsLoadingPlugin({
  externals: {
    lodash: {
      libraryName: 'Lodash',
      url: '……',
    },
    'lodash-es': {
      libraryName: 'Lodash',
      url: '……',
    }
  }
})

Will generate the following webpack externals config:

externals: {
  lodash: 'lynx[Symbol.for("__LYNX_EXTERNAL_GLOBAL__")].Lodash',
  'lodash-es': 'lynx[Symbol.for("__LYNX_EXTERNAL_GLOBAL__")].Lodash',
}

You can pass an array to specify subpath of the external. Same as https://webpack.js.org/configuration/externals/\#string-1. For example:

ExternalsLoadingPlugin({
  externals: {
    preact: {
      libraryName: ['ReactLynx', 'Preact'],
      url: '……',
      async: false,
    },
  }
})

Will generate the following webpack externals config:

externals: {
  preact: 'lynx[Symbol.for("__LYNX_EXTERNAL_GLOBAL__")].ReactLynx.Preact',
}

With the default async: true, a promise external is generated instead, which picks the subpath after the library promise resolves:

externals: {
  preact: 'promise Promise.resolve(lynx[Symbol.for("__LYNX_EXTERNAL_GLOBAL__")]["ReactLynx"]).then(function (m) { return m["Preact"]; })',
}

mainThread?

LayerOptions

(Optional) The options of the main-thread layer.

retries?

number

(Optional) The number of additional attempts when fetching the external bundle times out (response.code === -2).

timeout?

number

(Optional) The wait time in milliseconds.

url?

string | (() => string | Promise<string>)

(Optional) A bundle URL or a standalone resolver evaluated on first import.

Resolvers must not capture build-time variables. A string result preserves synchronous loading; a Promise result requires asynchronous loading.

Use this when the external bundle is hosted outside the current build output, such as on a CDN. If both url and bundlePath are provided,url takes precedence because it is already the fully resolved address.