加载器 (Loader) 实验性
TIP
提供此服务的插件:@cordisjs/plugin-loader。
这是一个内置插件,无需在配置文件中声明。
配置单元
ts
interface EntryOptions {
id: string
name: string
confg?: any
group?: boolean | null
disabled?: boolean | null
inject?: Inject | null
isolate?: Dict<true | string> | null
}
实例方法
ctx.loader.locate(ctx?)
- ctx:
Context
上下文,默认值为当前上下文 - 返回值:
string | undefined
获取一个上下文所属的 Entry ID。
ctx.loader.resolve(id)
- id:
string
配置单元 ID - 返回值:
Entry
获取配置单元。
ctx.loader.create(options, parent, position?)
- options:
Omit<EntryOptions, 'id'>
配置单元 - parent:
string | null
父级配置单元 ID - position:
number
插入位置,默认值为Infinity
- 返回值:
Promise<string>
创建配置单元。
ctx.loader.remove(id)
- id:
string
配置单元 ID
移除配置单元。
ctx.loader.update(id, options, parent?, position?)
- id:
string
配置单元 ID - options:
Omit<EntryOptions, 'id' | 'name'>
配置单元 - parent:
string | null
父级配置单元 ID - position:
number
插入位置
修改配置单元。所有 options
中包含的字段都会被更新。id
和 name
字段无法被更新。
如果传入了 parent
参数,则会将配置单元移动到新的父级配置单元下。
ctx.loader.import(name)
- name:
string
模块名称 - 返回值:
Promise<any>
从配置文件加载模块。
类:Entry
entry.id
- 类型:
string
配置单元 ID。
entry.disabled
- 类型:
boolean
是否禁用。此字段与 options.disabled
有所不同。
entry.options
- 类型:
EntryOptions
配置单元选项。