Bundler
A plugin type: Turns an asset graph into a bundle graph
Bundlers accept the entire asset graph and modify it to add bundle nodes that group the assets into output bundles.
import { Bundler } from "@parcel/plugin";
export default new Bundler({
async bundle({ graph }) {
// ...
},
async optimize({ graph }) {
// ...
},
});
ΒΆ Relevant API
TraversalActions parcel/packages/core/types/index.js:789
Used to control a traversal
interface TraversalActionsΒ {
skipChildren(): void,
stop(): void,
}
Referenced by:
GraphTraversalCallbackGraphVisitor parcel/packages/core/types/index.js:800
Essentially GraphTraversalCallback, but allows adding specific node enter and exit callbacks.
Type
type GraphVisitor<TNode, TContext> = GraphTraversalCallback<TNode, TContext> | {|
enter?: GraphTraversalCallback<TNode, TContext>,
exit?: GraphTraversalCallback<TNode, TContext>,
|};
Referenced by:
Bundle, BundleGraph, MutableBundleGraphGraphTraversalCallback parcel/packages/core/types/index.js:813
A generic callback for graph traversals
Parameter Descriptions
context: The parent node's return value is passed as a parameter to the children's callback. This can be used to forward information from the parent to children in a DFS (unlike a global variable).
Type
type GraphTraversalCallback<TNode, TContext> = (node: TNode, context: ?TContext, actions: TraversalActions) => ?TContext;
Referenced by:
GraphVisitorBundleTraversable parcel/packages/core/types/index.js:822
Type
type BundleTraversable = {|
+type: 'asset',
value: Asset,
|} | {|
+type: 'dependency',
value: Dependency,
|};
Referenced by:
BundleBundlerBundleGraphTraversable parcel/packages/core/types/index.js:829
Type
type BundlerBundleGraphTraversable = {|
+type: 'asset',
value: Asset,
|} | {|
+type: 'dependency',
value: Dependency,
|};
Referenced by:
MutableBundleGraphCreateBundleOpts parcel/packages/core/types/index.js:845
Options for MutableBundleGraph's createBundle.
If an entryAsset is provided, uniqueKey (for the bundle id),
type, and env will be inferred from the entryAsset.
If an entryAsset is not provided, uniqueKey (for the bundle id),
type, and env must be provided.
isSplittable defaults to entryAsset.isSplittable or false
Type
type CreateBundleOpts = {|
+uniqueKey?: string,
+entryAsset: Asset,
+target: Target,
+isEntry?: ?boolean,
+isInline?: ?boolean,
+isSplittable?: ?boolean,
+type?: ?string,
+env?: ?Environment,
+pipeline?: ?string,
|} | {|
+uniqueKey: string,
+entryAsset?: Asset,
+target: Target,
+isEntry?: ?boolean,
+isInline?: ?boolean,
+isSplittable?: ?boolean,
+type: string,
+env: Environment,
+pipeline?: ?string,
|};
Referenced by:
MutableBundleGraphBundle parcel/packages/core/types/index.js:901
A Bundle (a collection of assets)
interface BundleΒ {
+id: string,
+hashReference: string,
filePath it will be replace with the real hash at the end.
+type: string,
+env: Environment,
+filePath: ?FilePath,
hashReference before the optimizer ran.
+isEntry: ?boolean,
+isInline: ?boolean,
+isSplittable: ?boolean,
+target: Target,
+stats: Stats,
getEntryAssets(): Array<Asset>,
getMainEntry(): ?Asset,
hasAsset(Asset): boolean,
hasDependency(Dependency): boolean,
traverseAssets<TContext>(visit: GraphVisitor<Asset, TContext>): ?TContext,
traverse<TContext>(visit: GraphVisitor<BundleTraversable, TContext>): ?TContext,
}
Referenced by:
BundleGraph, MutableBundleGraph, NamedBundle, Namer, OptimizingProgressEvent, Packager, PackagingProgressEventNamedBundle parcel/packages/core/types/index.js:934
A Bundle that got named by a Namer
interface NamedBundle extends BundleΒ {
+publicId: string,
+filePath: FilePath,
+name: string,
+displayName: string,
}
Referenced by:
BuildSuccessEvent, Optimizer, OptimizingProgressEvent, Packager, PackagingProgressEvent, RuntimeBundleGroup parcel/packages/core/types/index.js:945
A collection of sibling bundles (which are stored in the BundleGraph) that should be loaded together (in order).
type BundleGroupΒ = {|
+target: Target,
+entryAssetId: string,
|}
Referenced by:
BundleGraph, MutableBundleGraphMutableBundleGraph parcel/packages/core/types/index.js:954
A BundleGraph in the Bundler that can be modified
interface MutableBundleGraph extends BundleGraph<Bundle>Β {
addAssetGraphToBundle(Asset, Bundle, shouldSkipDependency?: (Dependency) => boolean): void,
addEntryToBundle(Asset, Bundle, shouldSkipDependency?: (Dependency) => boolean): void,
addBundleToBundleGroup(Bundle, BundleGroup): void,
createAssetReference(Dependency, Asset, Bundle): void,
createBundleReference(Bundle, Bundle): void,
createBundle(CreateBundleOpts): Bundle,
createBundleGroup(Dependency, Target): BundleGroup,
getDependencyAssets(Dependency): Array<Asset>,
getParentBundlesOfBundleGroup(BundleGroup): Array<Bundle>,
getTotalSize(Asset): number,
removeAssetGraphFromBundle(Asset, Bundle): void,
removeBundleGroup(bundleGroup: BundleGroup): void,
internalizeAsyncDependency(bundle: Bundle, dependency: Dependency): void,
bundle.
traverse<TContext>(GraphVisitor<BundlerBundleGraphTraversable, TContext>): ?TContext,
traverseContents<TContext>(GraphVisitor<BundlerBundleGraphTraversable, TContext>): ?TContext,
}
Referenced by:
Bundler, CreateBundleOptsBundleGraph parcel/packages/core/types/index.js:992
A Graph that contains Bundle-s, Asset-s, Dependency-s, BundleGroup-s
interface BundleGraph<TBundle: Bundle>Β {
getAssetById(id: string): Asset,
getAssetPublicId(asset: Asset): string,
getBundles(): Array<TBundle>,
getBundleGroupsContainingBundle(bundle: Bundle): Array<BundleGroup>,
getBundlesInBundleGroup(bundleGroup: BundleGroup): Array<TBundle>,
getChildBundles(bundle: Bundle): Array<TBundle>,
getParentBundles(bundle: Bundle): Array<TBundle>,
getReferencedBundles(bundle: Bundle, opts?: {|
recursive: boolean
|}): Array<TBundle>,
getDependencies(asset: Asset): Array<Dependency>,
getIncomingDependencies(asset: Asset): Array<Dependency>,
getAssetWithDependency(dep: Dependency): ?Asset,
resolveAsyncDependency(dependency: Dependency, bundle: ?Bundle): ?({|
type: 'bundle_group',
value: BundleGroup,
|} | {|
type: 'asset',
value: Asset,
|}),
isDependencySkipped(dependency: Dependency): boolean,
getDependencyResolution(dependency: Dependency, bundle: ?Bundle): ?Asset,
getReferencedBundle(dependency: Dependency, bundle: Bundle): ?TBundle,
findBundlesWithAsset(Asset): Array<TBundle>,
findBundlesWithDependency(Dependency): Array<TBundle>,
isAssetReachableFromBundle(asset: Asset, bundle: Bundle): boolean,
findReachableBundleWithAsset(bundle: Bundle, asset: Asset): ?TBundle,
isAssetReferencedByDependant(bundle: Bundle, asset: Asset): boolean,
hasParentBundleOfType(bundle: Bundle, type: string): boolean,
resolveSymbol(asset: Asset, symbol: Symbol, boundary: ?Bundle): SymbolResolution,
asset exports symbol, try to find the asset where the corresponding variable lives (resolves re-exports). Stop resolving transitively once boundary was left (bundle.hasAsset(asset) === false), then result.symbol is undefined.
getExportedSymbols(asset: Asset, boundary: ?Bundle): Array<ExportSymbolResolution>,
traverseBundles<TContext>(visit: GraphVisitor<TBundle, TContext>, startBundle: ?Bundle): ?TContext,
getUsedSymbols(Asset | Dependency): $ReadOnlySet<Symbol>,
}
Referenced by:
BuildSuccessEvent, BundleGroup, Bundler, BundlingProgressEvent, MutableBundleGraph, Namer, Optimizer, Packager, RuntimeBundleResult parcel/packages/core/types/index.js:1066
type BundleResultΒ = {|
+contents: Blob,
+ast?: AST,
+map?: ?SourceMap,
+type?: string,
|}
Referenced by:
Optimizer, PackagerBundler parcel/packages/core/types/index.js:1102
Turns an asset graph into a BundleGraph.
bundle and optimize run in series and are functionally identitical.
type BundlerΒ = {|
loadConfig?: ({|
options: PluginOptions,
logger: PluginLogger,
|}) => Async<ConfigOutput>,
bundle({|
bundleGraph: MutableBundleGraph,
config: ?ConfigResult,
options: PluginOptions,
logger: PluginLogger,
|}): Async<void>,
optimize({|
bundleGraph: MutableBundleGraph,
config: ?ConfigResult,
options: PluginOptions,
logger: PluginLogger,
|}): Async<void>,
|}