執行時期

外掛類型:以編程方式將資產憑空插入到套件中

執行時期 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>>,
|}