运行时
一个插件类型:以凭空编程方式将资源插入打包
运行时 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
A "synthetic" asset that will be inserted into the bundle graph.
type RuntimeAsset = {|
+filePath: FilePath,
+code: string,
+dependency?: Dependency,
+isEntry?: boolean,
+env?: EnvironmentOptions,
+priority?: RuntimeAssetPriority,
|}
Referenced by:
RuntimeRuntime 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>>,
|}