运行时
一种插件类型:以编程方式将资产从无到有插入到包中
运行时 API 处于实验阶段,因此可能会发生变化,即使在次要更新之间也是如此。
运行时接受一个包并返回要插入该包的资产。
import { Runtime } from "@parcel/plugin";
export default new Runtime({
async apply({ bundle, bundleGraph }) {
// ...
return assets;
},
}); 相关 API
#RuntimeAsset parcel/packages/core/types/index.js:1619
一个将被插入到包图中的“合成”资产。
type RuntimeAsset = {| +filePath: FilePath, +code: string, +dependency?: Dependency, +isEntry?: boolean, +env?: EnvironmentOptions, +priority?: RuntimeAssetPriority, |} 被引用
运行时Runtime parcel/packages/core/types/index.js:1631
type Runtime<ConfigType> = {| loadConfig?: ({|
config: Config,
options: PluginOptions,
logger: PluginLogger,
|}) => Promise<ConfigType> | ConfigType, apply({|
bundle: NamedBundle,
bundleGraph: BundleGraph<NamedBundle>,
config: ConfigType,
options: PluginOptions,
logger: PluginLogger,
|}): Async<void | RuntimeAsset | Array<RuntimeAsset>>, |}