Interface: PluginExternalValue
pluginExternalBundle 接受的 external bundle 引用。
Extends
Omit<ExternalValue,"url">
Properties
async?
optionalasync?:boolean| ((context:object) =>boolean)
是否异步加载资源。
回调会序列化到 bundle 中,在运行时接收 SystemInfo(不可用时使用 lynx.SystemInfo)。它必须是独立的箭头函数或函数表达式,不能引用闭包变量,并且必须同步返回布尔值。使用回调的 external 始终采用 promise 模块语义,即使回调选择了同步加载。
Example
Default Value
true
Inherited from
Omit.async
background?
optionalbackground?:LayerOptions
后台 layer 的选项。
Default Value
undefined
Inherited from
Omit.background
bundlePath?
optionalbundlePath?:string
基于运行时 public path 解析的 bundle 路径。
当 external bundle 需要作为当前项目的一部分被产出或提供服务时,优先使用该选项而非 url。pluginExternalBundle 可以利用这些信息管理本地 bundle 文件,同时运行时会使最终
URL 与当前生效的 publicPath 保持一致。
Overrides
Omit.bundlePath
libraryName?
optionallibraryName?:string|string[]
库的名称。与 https://webpack.js.org/configuration/externals/#string 相同。
默认情况下,库名称与 externals 的 key 相同。例如:
配置
将生成以下 webpack externals 配置:
如果一个 external bundle 包含多个模块,应设置相同的库名称,以确保它只被加载一次。例如:
将生成以下 webpack externals 配置:
可以传入数组来指定 external 的子路径。与 https://webpack.js.org/configuration/externals/#string-1 相同。例如:
将生成以下 webpack externals 配置:
在默认的 async: true 下,会改为生成一个 promise external,它会在库的 promise resolve 之后再取出子路径:
Default Value
undefined
Example
Inherited from
Omit.libraryName
mainThread?
optionalmainThread?:LayerOptions
主线程 layer 的选项。
Default Value
undefined
Inherited from
Omit.mainThread
retries?
optionalretries?:number
获取外部 bundle 超时(response.code === -2)时的额外重试次数。
Default Value
0
Inherited from
Omit.retries
timeout?
optionaltimeout?:number
等待时间,单位为毫秒。
Default Value
2000
Inherited from
Omit.timeout
url?
optionalurl?:NonNullable<string| (() =>string|Promise<string>) |undefined>
Bundle 的 URL。
仅当 external bundle 位于当前构建产物之外、且不应由 pluginExternalBundle 产出或提供服务时才使用该选项。
Deprecated
建议优先使用 bundlePath,它通过运行时 public
path 解析,并允许上层工具管理资源产出。