API
The remaining types specified in `@parcel/plugin`
FilePath packages-v3/plugin/src/types.ts:13
Type
type FilePath = string;
Referenced by:
Asset, Bundle, Namer, PluginOptions, ResolveFn, ResolveResult, TargetPackageName packages-v3/plugin/src/types.ts:15
Type
type PackageName = string;
Referenced by:
TargetSemverRange packages-v3/plugin/src/types.ts:16
Type
type SemverRange = string;
Referenced by:
Dependency, DependencyOptionsDependencySpecifier packages-v3/plugin/src/types.ts:18
See Dependency
Type
type DependencySpecifier = string;
Referenced by:
Dependency, DependencyOptions, ResolverAsync packages-v3/plugin/src/types.ts:21
Plugins may return either a value or a promise for it.
Type
type Async<T> = T | Promise<T>;
Referenced by:
Namer, Optimizer, Reporter, Resolver, TransformerJSONObject packages-v3/plugin/src/types.ts:24
A JSON object (as in "map")
type JSONObject = {
[key: string]: JSONValue;
}
Referenced by:
JSONValueJSONValue packages-v3/plugin/src/types.ts:25
Type
type JSONValue =
| null
| boolean
| number
| string
| Array<JSONValue>
| JSONObject;
Referenced by:
JSONObjectSourceMapJSON packages-v3/plugin/src/types.ts:34
A source map in the standard JSON format (version 3).
type SourceMapJSON = {
version: number;
sources: Array<string>;
mappings: string;
names?: Array<string>;
sourcesContent?: Array<string | null>;
sourceRoot?: string;
file?: string;
[key: string]: unknown;
}
Referenced by:
Asset, MutableAssetLocation packages-v3/plugin/src/types.ts:46
Line/column positions are 1-based (so 1 is the first line/column).
type Location = {
readonly line: number;
readonly column: number;
}
Referenced by:
DependencyOptions, DiagnosticCodeHighlight, SourceLocationSourceLocation packages-v3/plugin/src/types.ts:51
type SourceLocation = {
readonly filePath: string;
readonly start: Location;
inclusive
readonly end: Location;
exclusive
}
Referenced by:
DependencyDiagnosticSeverity packages-v3/plugin/src/types.ts:67
- error: Fails the build.
- warning: Logged, but does not fail the build.
- sourceError: An error in source code in the project, or a warning in node_modules.
- info: An informative message.
Type
type DiagnosticSeverity = 'error' | 'warning' | 'sourceError' | 'info';
Referenced by:
DiagnosticOptionsDiagnosticCodeHighlight packages-v3/plugin/src/types.ts:69
type DiagnosticCodeHighlight = {
start: Location;
Location of the first character that should get highlighted for this highlight.
end?: Location;
Location of the last character that should get highlighted for this highlight. Defaults to start.
message?: string | null;
A message that should be displayed at this location in the code.
}
Referenced by:
DiagnosticCodeFrameDiagnosticCodeFrame packages-v3/plugin/src/types.ts:83
Describes how to format a code frame. A code frame is a visualization of a piece of code with a certain amount of code highlights that point to certain chunk(s) inside the code.
type DiagnosticCodeFrame = {
code?: string | null;
The contents of the source file, if different from the file. If omitted, the file is read.
filePath?: string | null;
Absolute path of the file this code frame is about. Diagnostics passed to reporters
use url instead.
url?: string | null;
URL of the file this code frame is about. Files on disk use file: URLs.
language?: string | null;
Language (file extension) of the code, used for syntax highlighting.
codeHighlights: Array<DiagnosticCodeHighlight>;
}
Referenced by:
DiagnosticOptionsDiagnosticOptions packages-v3/plugin/src/types.ts:104
A style agnostic way of emitting errors, warnings and info. Reporters are responsible for rendering the message, codeframes, hints, ...
Diagnostics passed to reporters have every field.
type DiagnosticOptions = {
message: string;
This is the message you want to log.
origin?: string | null;
Name of plugin or file that threw this error. Defaults to the plugin's name in .parcelrc.
codeFrames?: Array<DiagnosticCodeFrame>;
Code frames point to certain location(s) in the file(s) this diagnostic is linked to.
hints?: Array<string>;
A list of strings that suggest ways to resolve this issue
severity?: DiagnosticSeverity;
Default value: 'error'
documentationURL?: string | null;
A URL to documentation to learn more about the diagnostic.
}
Referenced by:
BuildFailureEvent, Diagnostic, LogEventLogLevel packages-v3/plugin/src/types.ts:119
Type
type LogLevel = 'none' | 'error' | 'warn' | 'info' | 'verbose';
Referenced by:
LogEvent, PluginOptionsBuildMode packages-v3/plugin/src/types.ts:120
Type
type BuildMode = 'development' | 'production' | string;
Referenced by:
PluginOptionsHMROptions packages-v3/plugin/src/types.ts:122
type HMROptions = {
readonly host: string;
readonly port: number;
}
Referenced by:
PluginOptionsPluginOptions packages-v3/plugin/src/types.ts:127
interface PluginOptions {
readonly mode: BuildMode;
readonly env: Readonly<Record<string, string>>;
readonly logLevel: LogLevel;
readonly hmrOptions: HMROptions | undefined;
readonly projectRoot: FilePath;
}
Referenced by:
Namer, Optimizer, ReporterContext, Resolver, TransformerEngines packages-v3/plugin/src/types.ts:139
Corresponds to pkg#engines, resolved to minimum versions, which are
formatted like >= 18.2.
type Engines = {
readonly browsers: string;
The minimum browser versions, e.g. chrome >= 63, firefox >= 67, safari >= 11.1. Empty if none.
readonly electron: string | null;
readonly node: string | null;
readonly parcel: string | null;
}
Referenced by:
TargetTargetSourceMapOptions packages-v3/plugin/src/types.ts:148
Corresponds to pkg#targets.*.sourceMap
type TargetSourceMapOptions = {
readonly sourceRoot: string | null;
readonly inline: boolean | null;
readonly inlineSources: boolean | null;
}
Referenced by:
TargetEnvironmentContext packages-v3/plugin/src/types.ts:155
In which environment the output should run (influces e.g. bundle loaders)
Type
type EnvironmentContext =
| 'browser'
| 'web-worker'
| 'service-worker'
| 'worklet'
| 'node'
| 'electron-main'
| 'electron-renderer'
| 'react-client'
| 'react-server';
Referenced by:
TargetOutputFormat packages-v3/plugin/src/types.ts:167
The JS module format for the bundle output
Type
type OutputFormat = 'esmodule' | 'commonjs' | 'global';
Referenced by:
TargetSourceType packages-v3/plugin/src/types.ts:169
Type
type SourceType = 'script' | 'module';
Referenced by:
TargetTarget packages-v3/plugin/src/types.ts:174
Where and how an asset or bundle will run.
interface Target {
readonly distDir: FilePath;
The output folder
readonly publicUrl: string;
readonly engines: Engines;
readonly includeNodeModules:
| boolean
| Array<PackageName>
| Record<PackageName, boolean>;
Whether to include all/none packages (true / false), an array of package names to include, or an object (of a package is not specified, it's included).
readonly sourceMap: TargetSourceMapOptions | null;
readonly environment: EnvironmentContext;
readonly outputFormat: OutputFormat;
readonly sourceType: SourceType;
readonly isLibrary: boolean;
Whether this is a library build (e.g. less loaders)
readonly shouldOptimize: boolean;
Whether the output should be minified.
isBrowser(): boolean;
Whether environment specifies a browser context.
isNode(): boolean;
Whether environment specifies a node context.
isElectron(): boolean;
Whether environment specifies an electron context.
isServer(): boolean;
Whether environment specifies a server context (node or react-server).
isWorker(): boolean;
Whether environment specifies a worker context.
isWorklet(): boolean;
Whether environment specifies a worklet context.
}
Referenced by:
Asset, Bundle, Dependency, DependencyOptionsDependencyPriority packages-v3/plugin/src/types.ts:218
Type
type DependencyPriority = 'sync' | 'parallel' | 'lazy';
Referenced by:
Dependency, DependencyOptionsSpecifierType packages-v3/plugin/src/types.ts:219
Type
type SpecifierType = 'commonjs' | 'esm' | 'url' | 'custom';
Referenced by:
Dependency, DependencyOptions, ResolveOptionsBundleBehavior packages-v3/plugin/src/types.ts:220
Type
type BundleBehavior = 'inline' | 'isolated';
Referenced by:
Asset, Bundle, Dependency, DependencyOptions, MutableAssetImportType packages-v3/plugin/src/types.ts:230
How the resolved asset is used by the importing asset.
- javascript: Imported as a JavaScript module.
- stylesheet: Imported as a CSS stylesheet.
- url: Referenced by URL.
- text: Imported as a string.
- bytes: Imported as binary data.
Type
type ImportType = 'javascript' | 'stylesheet' | 'url' | 'text' | 'bytes';
Referenced by:
Dependency, DependencyOptionsPackageCondition packages-v3/plugin/src/types.ts:233
The package.json "exports" and "imports" conditions supported by Parcel.
Type
type PackageCondition =
| 'import'
| 'require'
| 'module'
| 'node'
| 'browser'
| 'worker'
| 'worklet'
| 'electron'
| 'development'
| 'production'
| 'types'
| 'default'
| 'style'
| 'sass'
| 'less'
| 'stylus'
| 'react-server'
| 'source';
Referenced by:
Dependency, DependencyOptionsBundle packages-v3/plugin/src/types.ts:585
A Bundle (a collection of assets)
Bundles can only be accessed during the plugin call they were passed to.
interface Bundle {
readonly type: string;
The type of the bundle.
readonly target: Target;
The bundle's target.
readonly isEntry: boolean;
Whether the bundle is an entry.
readonly needsStableName: boolean;
Indicates that the bundle's file name should be stable over time, even when the content of the bundle changes. This is useful for entries that a user would manually enter the URL for, as well as for things like service workers or RSS feeds, where the URL must remain consistent over time.
readonly bundleBehavior: BundleBehavior | undefined;
Controls the behavior of the bundle.
- inline: Inline bundles are not written to a separate file, but embedded into the parent bundle.
- isolated: The bundle will be isolated from its parents. Shared assets will be duplicated.
readonly hashReference: string;
A placeholder for the bundle's content hash. A namer must include it exactly once in the name of a bundle that may be content hashed. It is replaced with a content hash of the bundle after packaging and optimizing.
readonly filePath: FilePath | null;
The absolute path the bundle is written to, once it is known. null for inline bundles,
before the bundle is named, and while a content hashed name is unknown.
readonly name: string | null;
The bundle's name: its file path relative to its target's distDir.
null until it can be read, i.e. before the bundle is named, or while a content hashed
name is unknown.
getEntryAssets(): Array<Asset>;
Returns the assets that are executed immediately when the bundle is loaded. Some bundles may not have any entry assets, for example, shared bundles.
getMainEntry(): Asset | undefined;
Returns the main entry of the bundle, which will provide the bundle's exports. Some bundles do not have a main entry, for example, shared bundles.
hasAsset(asset: Asset): boolean;
Returns whether the bundle includes the given asset.
}
Referenced by:
BundleGraph, Namer, OptimizerBundleGraph packages-v3/plugin/src/types.ts:649
A Graph that contains Bundle-s.
interface BundleGraph {
getBundles(): Array<Bundle>;
Returns a list of bundles in the bundle graph.
getEntryBundles(): Array<Bundle>;
Returns a list of entry bundles.
getReferencedBundles(
bundle: Bundle,
options?: {
recursive?: boolean;
},
): Array<Bundle>;
Returns a list of bundles that are referenced by this bundle.
getBundlesInBundleGroup(bundle: Bundle): Array<Bundle>;
Returns the bundles that code in the bundle's execution context may load: everything reachable through bundle references and Parcel's loader, without entering other execution contexts (e.g. workers). The bundle itself is not included.
getBundleDependencies(bundle: Bundle): Array<Bundle>;
Returns the bundles that dependencies of the bundle's assets resolve to, e.g. lazy, isolated, inline and URL references.
getResolvedAsset(dependency: Dependency): Asset | undefined;
Returns the asset that the dependency resolved to, if any.
getReferencedBundle(dependency: Dependency): Bundle | undefined;
Returns the bundle that the dependency references, if it resolved to another bundle.
}
Referenced by:
BuildSuccessEvent, Namer, OptimizerDiagnostic packages-v3/plugin/src/PluginAPI.ts:53
An error carrying one or more diagnostics. Throw it from a plugin to fail with them, or pass
it to a console method to log them at that level.
class Diagnostic extends Error {
readonly diagnostics: Array<DiagnosticOptions>;
constructor(diagnostic: DiagnosticOptions | Array<DiagnosticOptions>);
}