API

`@parcel/types` 中指定的其餘類型

最重要的資料類型列在相關外掛類型的頁面上。

AST parcel/packages/core/types/index.js:18

特定於外掛的 ASTany

類型
type AST = _AST;
參照
BaseAssetBundleResultMutableAssetTransformerTransformerResult

ConfigResult parcel/packages/core/types/index.js:19

類型
type ConfigResult = _ConfigResult;
參照
MultiThreadValidator

ConfigResultWithFilePath parcel/packages/core/types/index.js:21

特定於外掛的組態結果,any

type ConfigResultWithFilePath<T> = {|
  contents: T,
  filePath: FilePath,
|}
參照
組態

EnvMap parcel/packages/core/types/index.js:26

process.env

類型
type EnvMap = typeof process.env;
參照
InitialParcelOptionsPluginOptions

JSONValue parcel/packages/core/types/index.js:28

類型
type JSONValue = null | void | boolean | number | string | Array<JSONValue> | JSONObject;

JSONObject parcel/packages/core/types/index.js:38

一個 JSON 物件(如「map」)

type JSONObject = {
}
參照
JSONValueMetaResolveResult

GlobMap parcel/packages/core/types/index.js:49

設定檔中指定為對應至 T 的管線

type GlobMap<T> = {
}

原始 Parcel 設定檔管線 parcel/packages/core/types/index.js:51

類型
type RawParcelConfigPipeline = Array<PackageName>;
參照
原始 Parcel 設定檔

HMR 選項 parcel/packages/core/types/index.js:53

type HMROptions = {
  port?: number,
  host?: string,
}
參照
InitialParcelOptionsPluginOptions

原始 Parcel 設定檔 parcel/packages/core/types/index.js:56

.parcelrc 的格式

type RawParcelConfig = {|
  extends?: PackageName | FilePath | Array<PackageName | FilePath>,
  resolvers?: RawParcelConfigPipeline,
  transformers?: {
    [Glob]: RawParcelConfigPipeline,
    ...
  },
  bundler?: PackageName,
  namers?: RawParcelConfigPipeline,
  runtimes?: RawParcelConfigPipeline,
  packagers?: {
    [Glob]: PackageName,
    ...
  },
  optimizers?: {
    [Glob]: RawParcelConfigPipeline,
    ...
  },
  compressors?: {
    [Glob]: RawParcelConfigPipeline,
    ...
  },
  reporters?: RawParcelConfigPipeline,
  validators?: {
    [Glob]: RawParcelConfigPipeline,
    ...
  },
|}
參照
已解析的 Parcel 設定檔

已解析的 Parcel 設定檔 parcel/packages/core/types/index.js:71

已解析所有套件名稱的 .parcelrc

type ResolvedParcelConfigFile = {|
  ...RawParcelConfig,
  +filePath: FilePath,
  +resolveFrom?: FilePath,
|}

引擎 parcel/packages/core/types/index.js:78

對應至 pkg#engines

type Engines = {
  +browsers?: string | Array<string>,
  +electron?: SemverRange,
  +node?: SemverRange,
  +parcel?: SemverRange,
}
參照
環境環境選項初始 Parcel 選項PackageJSON套件目標描述

目標原始碼對應選項 parcel/packages/core/types/index.js:87

對應至 pkg#targets.*.sourceMap

type TargetSourceMapOptions = {|
  +sourceRoot?: string,
  +inline?: boolean,
  +inlineSources?: boolean,
|}
參照
環境, EnvironmentOptions, PackageTargetDescriptor

目標 parcel/packages/core/types/index.js:96

PackageTargetDescriptor 的已剖析版本

interface Target {
  +distEntry: ?FilePath,

輸入的輸出檔名

  +distDir: FilePath,

輸出資料夾

  +env: Environment,
  +name: string,
  +publicUrl: string,
  +loc: ?SourceLocation,

建立此 目標 的位置,例如 package.json#main

}
參照
套件, 套件圖, 套件群組, 建立套件選項, 相依性, 可變套件圖, PackageTargetDescriptor

環境內容 parcel/packages/core/types/index.js:109

輸出應執行的環境(例如影響套件載入器)

類型
type EnvironmentContext = 'browser' | 'web-worker' | 'service-worker' | 'worklet' | 'node' | 'electron-main' | 'electron-renderer';
參照
環境, EnvironmentOptions, PackageTargetDescriptor

輸出格式 parcel/packages/core/types/index.js:119

套件輸出的 JS 模組格式

類型
type OutputFormat = 'esmodule' | 'commonjs' | 'global';
參照
環境, EnvironmentOptions, 初始 Parcel 選項, PackageTargetDescriptor

套件目標描述 parcel/packages/core/types/index.js:126

pkg#targets.* 的格式
請參閱 環境目標

type PackageTargetDescriptor = {|
  +context?: EnvironmentContext,
  +engines?: Engines,
  +includeNodeModules?: boolean | Array<PackageName> | {
    [PackageName]: boolean,
    ...
  },
  +outputFormat?: OutputFormat,
  +publicUrl?: string,
  +distDir?: FilePath,
  +sourceMap?: boolean | TargetSourceMapOptions,
  +isLibrary?: boolean,
  +optimize?: boolean,
  +scopeHoist?: boolean,
  +source?: FilePath | Array<FilePath>,
|}
參照
PackageJSONTargetTargetDescriptor

TargetDescriptor parcel/packages/core/types/index.js:148

使用 JS API 時的目標格式。
(與 PackageTargetDescriptor 相同,但需要 distDir。)

type TargetDescriptor = {|
  ...PackageTargetDescriptor,
  +distDir: FilePath,
  +distEntry?: FilePath,
|}
參照
InitialParcelOptions

SourceType parcel/packages/core/types/index.js:154

類型
type SourceType = 'script' | 'module';
參照
EnvironmentEnvironmentOptions

EnvironmentOptions parcel/packages/core/types/index.js:159

在建立 Environment 時會使用這個 (請參閱)。

type EnvironmentOptions = {|
  +context?: EnvironmentContext,
  +engines?: Engines,
  +includeNodeModules?: boolean | Array<PackageName> | {
    [PackageName]: boolean,
    ...
  },
  +outputFormat?: OutputFormat,
  +sourceType?: SourceType,
  +isLibrary?: boolean,
  +shouldOptimize?: boolean,
  +shouldScopeHoist?: boolean,
  +sourceMap?: ?TargetSourceMapOptions,
  +loc?: ?SourceLocation,
|}
參照
DependencyOptionsMutableAssetRuntimeAssetTransformerResult

VersionMap parcel/packages/core/types/index.js:187

已解析的瀏覽器清單,例如:


{
  edge: '76',
  firefox: '67',
  chrome: '63',
  safari: '11.1',
  opera: '50',
}
type VersionMap = {
}
參照
Environment

EnvironmentFeature parcel/packages/core/types/index.js:192

類型
type EnvironmentFeature = 'esmodules' | 'dynamic-import' | 'worker-module' | 'service-worker-module' | 'import-meta-url' | 'arrow-functions';
參照
Environment

Environment parcel/packages/core/types/index.js:203

定義輸出套件的環境

interface Environment {
  +id: string,
  +context: EnvironmentContext,
  +engines: Engines,
  +includeNodeModules: boolean | Array<PackageName> | {
    [PackageName]: boolean,
    ...
  },

是否包含所有/沒有套件 (true / false)、包含的套件名稱陣列,或物件 (如果未指定套件,則包含)。

  +outputFormat: OutputFormat,
  +sourceType: SourceType,
  +isLibrary: boolean,

這是否為程式庫建置 (例如較少的載入器)

  +shouldOptimize: boolean,

輸出是否應縮小化。

  +shouldScopeHoist: boolean,

範圍提升是否已啟用。

  +sourceMap: ?TargetSourceMapOptions,
  +loc: ?SourceLocation,
  isBrowser(): boolean,

context 是否指定瀏覽器內容。

  isNode(): boolean,

context 是否指定節點內容。

  isElectron(): boolean,

context 是否指定電子內容。

  isWorker(): boolean,

context 是否指定工作者內容。

  isWorklet(): boolean,

context 是否指定工作單元內容。

  isIsolated(): boolean,

context 是否指定隔離內容(無法存取其他已載入的祖先套件)。

  matchesEngines(minVersions: VersionMap, defaultValue?: boolean): boolean,
  supports(feature: EnvironmentFeature, defaultValue?: boolean): boolean,
}
參照
BaseAssetBundleConfigCreateBundleOptsDependencyEnvironmentOptionsPackageTargetDescriptorTargetTransformerResult

PackageDependencies parcel/packages/core/types/index.js:245

pkg#dependenciespkg#devDependenciespkg#peerDependencies 的格式

type PackageDependencies = {|
|}
參照
PackageJSON

PackageJSON parcel/packages/core/types/index.js:252

package.json 的格式

type PackageJSON = {
  name: PackageName,
  version: Semver,
  type?: 'module',
  main?: FilePath,
  module?: FilePath,
  types?: FilePath,
  browser?: FilePath | {
    [FilePath]: FilePath | boolean,
    ...
  },
  source?: FilePath | Array<FilePath>,
  alias?: {
    [PackageName | FilePath | Glob]: PackageName | FilePath | {|
      global: string
    |},
    ...
  },
  browserslist?: Array<string> | {
    [string]: Array<string>
  },
  engines?: Engines,
  targets?: {
    [string]: PackageTargetDescriptor,
    ...
  },
  dependencies?: PackageDependencies,
  devDependencies?: PackageDependencies,
  peerDependencies?: PackageDependencies,
  sideEffects?: boolean | FilePath | Array<FilePath>,
  bin?: string | {|
    [string]: FilePath
  |},
}
參照
組態

LogLevel parcel/packages/core/types/index.js:279

類型
type LogLevel = 'none' | 'error' | 'warn' | 'info' | 'verbose';
參照
InitialParcelOptionsPluginOptions

BuildMode parcel/packages/core/types/index.js:280

類型
type BuildMode = 'development' | 'production' | string;
參照
InitialParcelOptionsPluginOptions

DetailedReportOptions parcel/packages/core/types/index.js:281

type DetailedReportOptions = {|
  assetsPerBundle?: number,
|}
參照
InitialParcelOptionsPluginOptions

InitialParcelOptions parcel/packages/core/types/index.js:285

type InitialParcelOptions = {|
  +entries?: FilePath | Array<FilePath>,
  +config?: DependencySpecifier,
  +defaultConfig?: DependencySpecifier,
  +env?: EnvMap,
  +targets?: ?(Array<string> | {
    +[string]: TargetDescriptor,
    ...
  }),
  +shouldDisableCache?: boolean,
  +cacheDir?: FilePath,
  +mode?: BuildMode,
  +hmrOptions?: ?HMROptions,
  +shouldContentHash?: boolean,
  +serveOptions?: InitialServerOptions | false,
  +shouldAutoInstall?: boolean,
  +logLevel?: LogLevel,
  +shouldProfile?: boolean,
  +shouldPatchConsole?: boolean,
  +shouldBuildLazily?: boolean,
  +shouldBundleIncrementally?: boolean,
  +inputFS?: FileSystem,
  +outputFS?: FileSystem,
  +cache?: Cache,
  +workerFarm?: WorkerFarm,
  +packageManager?: PackageManager,
  +detailedReport?: ?DetailedReportOptions,
  +defaultTargetOptions?: {|
    +shouldOptimize?: boolean,
    +shouldScopeHoist?: boolean,
    +sourceMaps?: boolean,
    +publicUrl?: string,
    +distDir?: FilePath,
    +engines?: Engines,
    +outputFormat?: OutputFormat,
    +isLibrary?: boolean,
  |},
  +additionalReporters?: Array<{|
    packageName: DependencySpecifier,
    resolveFrom: FilePath,
  |}>,
|}

InitialServerOptions parcel/packages/core/types/index.js:332

type InitialServerOptions = {|
  +publicUrl?: string,
  +host?: string,
  +port: number,
  +https?: HTTPSOptions | boolean,
|}
參照
InitialParcelOptions

PluginOptions parcel/packages/core/types/index.js:339

interface PluginOptions {
  +mode: BuildMode,
  +env: EnvMap,
  +hmrOptions: ?HMROptions,
  +serveOptions: ServerOptions | false,
  +shouldBuildLazily: boolean,
  +shouldAutoInstall: boolean,
  +logLevel: LogLevel,
  +projectRoot: FilePath,
  +cacheDir: FilePath,
  +inputFS: FileSystem,
  +outputFS: FileSystem,
  +packageManager: PackageManager,
  +instanceId: string,
  +detailedReport: ?DetailedReportOptions,
}
參照
Bundler, Compressor, DedicatedThreadValidator, MultiThreadValidator, Namer, Optimizer, Packager, Reporter, Resolver, Runtime, Transformer

ServerOptions parcel/packages/core/types/index.js:356

type ServerOptions = {|
  +distDir: FilePath,
  +host?: string,
  +port: number,
  +https?: HTTPSOptions | boolean,
  +publicUrl?: string,
|}
參照
PluginOptions

HTTPSOptions parcel/packages/core/types/index.js:364

type HTTPSOptions = {|
  +cert: FilePath,
  +key: FilePath,
|}
參照
InitialServerOptions, ServerOptions

SourceLocation parcel/packages/core/types/index.js:372

來源位置是從 1 開始,表示行和欄從 1 開始

type SourceLocation = {|
  +filePath: string,
  +start: {|
    +line: number,
    +column: number,
  |},

包含

  +end: {|
    +line: number,
    +column: number,
  |},

不包含

|}
參照
AssetSymbols, Dependency, DependencyOptions, Environment, EnvironmentOptions, MutableAssetSymbols, MutableDependencySymbols, SymbolResolution, Target, TransformerResult

AssetSymbols parcel/packages/core/types/index.js:399

匯出名稱對應到資產的本地變數名稱的對應表。

interface AssetSymbols extends Iterable<[Symbol, {|
  local: Symbol,
  loc: ?SourceLocation,
  meta?: ?Meta,
|}]> {
  +isCleared: boolean,

資產的匯出是未知的,而不是空的。這是預設狀態。

  get(exportSymbol: Symbol): ?{|
    local: Symbol,
    loc: ?SourceLocation,
    meta?: ?Meta,
  |},
  hasExportSymbol(exportSymbol: Symbol): boolean,
  hasLocalSymbol(local: Symbol): boolean,
  exportSymbols(): Iterable<Symbol>,
}
參照
BaseAssetMutableAssetSymbols

MutableAssetSymbols parcel/packages/core/types/index.js:418

interface MutableAssetSymbols extends AssetSymbols {
  ensure(): void,

初始化對應表,將 isCleared 設為 false。

  set(exportSymbol: Symbol, local: Symbol, loc: ?SourceLocation, meta?: ?Meta): void,
  delete(exportSymbol: Symbol): void,
}
參照
MutableAsset

MutableDependencySymbols parcel/packages/core/types/index.js:435

isWeak 表示:符號未被父資產本身使用,僅僅被重新匯出

interface MutableDependencySymbols extends Iterable<[Symbol, {|
  local: Symbol,
  loc: ?SourceLocation,
  isWeak: boolean,
  meta?: ?Meta,
|}]> {
  ensure(): void,

初始化對應表,將 isCleared 設為 false。

  +isCleared: boolean,

匯入的符號是未知的,而不是空的。這是預設狀態。

  get(exportSymbol: Symbol): ?{|
    local: Symbol,
    loc: ?SourceLocation,
    isWeak: boolean,
    meta?: ?Meta,
  |},
  hasExportSymbol(exportSymbol: Symbol): boolean,
  hasLocalSymbol(local: Symbol): boolean,
  exportSymbols(): Iterable<Symbol>,
  set(exportSymbol: Symbol, local: Symbol, loc: ?SourceLocation, isWeak: ?boolean): void,
  delete(exportSymbol: Symbol): void,
}
參照
Dependency

DependencyPriority parcel/packages/core/types/index.js:469

類型
type DependencyPriority = 'sync' | 'parallel' | 'lazy';
參照
DependencyDependencyOptionsResolveResult

SpecifierType parcel/packages/core/types/index.js:470

類型
type SpecifierType = 'commonjs' | 'esm' | 'url' | 'custom';
參照
DependencyDependencyOptionsResolveOptions

File parcel/packages/core/types/index.js:631

type File = {|
  +filePath: FilePath,
  +hash?: string,
|}

DevDepOptions parcel/packages/core/types/index.js:790

type DevDepOptions = {|
  specifier: DependencySpecifier,
  resolveFrom: FilePath,
  range?: ?SemverRange,
  additionalInvalidations?: Array<{|
    specifier: DependencySpecifier,
    resolveFrom: FilePath,
    range?: ?SemverRange,
  |}>,

當此開發依賴項失效時,也會使這些依賴項失效。如果 parcel 外掛程式或其他父依賴項有自己的快取,而不是 Node 的 require 快取,這會很有用。

|}
參照
組態

Stats parcel/packages/core/types/index.js:874

type Stats = {|
  time: number,
  size: number,
|}
參照
AssetPackagedBundle

Blob parcel/packages/core/types/index.js:887

類型
type Blob = string | Buffer | Readable;
參照
BundleResultGenerateOutputOptimizerPackagerTransformerResult

PackagedBundle parcel/packages/core/types/index.js:1330

interface PackagedBundle extends NamedBundle {
  +filePath: FilePath,

已寫入的套件的絕對檔案路徑,包括最後的內容雜湊(如果有)。

  +stats: Stats,

套件的統計資料。

}
參照
BuildSuccessEvent

GlobInvalidation parcel/packages/core/types/index.js:1518

type GlobInvalidation = {|
  glob: Glob,
|}
參照
FileCreateInvalidation

FileInvalidation parcel/packages/core/types/index.js:1522

type FileInvalidation = {|
  filePath: FilePath,
|}
參照
FileCreateInvalidation

FileAboveInvalidation parcel/packages/core/types/index.js:1526

type FileAboveInvalidation = {|
  fileName: string,
  aboveFilePath: FilePath,
|}
參照
FileCreateInvalidation

RuntimeAssetPriority parcel/packages/core/types/index.js:1613

類型
type RuntimeAssetPriority = 'sync' | 'parallel';
參照
RuntimeAsset

BundledProgressEvent parcel/packages/core/types/index.js:1826

type BundledProgressEvent = {|
  +type: 'buildProgress',
  +phase: 'bundled',
  +bundleGraph: BundleGraph<NamedBundle>,
  +changedAssets: Map<string, Asset>,
|}
參照
BuildProgressEvent

ErrorWithCode parcel/packages/core/types/index.js:1923

interface ErrorWithCode extends Error {
  +code?: string,
}

IDisposable parcel/packages/core/types/index.js:1927

interface IDisposable {
  dispose(): mixed,
}

AsyncSubscription parcel/packages/core/types/index.js:1931

type AsyncSubscription = {|
  unsubscribe(): Promise<mixed>,
|}