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 website/generate-api-docs/example.flow:747
Used to control a traversal
interface TraversalActions {
skipChildren(): void,
stop(): void,
}
Referenced by:
GraphTraversalCallbackGraphVisitor website/generate-api-docs/example.flow:758
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, MutableBundleGraph, BundleGraphGraphTraversalCallback website/generate-api-docs/example.flow:771
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 propagate information from the parent to children (unlike a global variable).
Type
type GraphTraversalCallback<TNode, TContext> = (node: TNode, context: ?TContext, actions: TraversalActions) => ?TContext;
Referenced by:
GraphVisitorBundleTraversable website/generate-api-docs/example.flow:780
Type
type BundleTraversable = {|
+type: "asset",
value: Asset,
|} | {|
+type: "dependency",
value: Dependency,
|};
Referenced by:
BundleBundlerBundleGraphTraversable website/generate-api-docs/example.flow:787
Type
type BundlerBundleGraphTraversable = {|
+type: "asset",
value: Asset,
|} | {|
+type: "dependency",
value: Dependency,
|};
Referenced by:
MutableBundleGraphCreateBundleOpts website/generate-api-docs/example.flow:803
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.
Property Descriptions
isSplittable: defaults toentryAsset.isSplittableorfalse
Type
type CreateBundleOpts = {|
+uniqueKey?: string,
+entryAsset: Asset,
+target: Target,
+isEntry?: ?boolean,
+isInline?: ?boolean,
+isSplittable?: ?boolean,
+type?: ?string,
+env?: ?Environment,
|} | {|
+uniqueKey: string,
+entryAsset?: Asset,
+target: Target,
+isEntry?: ?boolean,
+isInline?: ?boolean,
+isSplittable?: ?boolean,
+type: string,
+env: Environment,
|};
Referenced by:
MutableBundleGraphSymbolResolution website/generate-api-docs/example.flow:832
Specifies a symbol in an asset
type SymbolResolution = {|
+asset: Asset,
+exportSymbol: CodeSymbol | string,
+symbol: void | null | CodeSymbol,
+loc: ?SourceLocation,
|}
Referenced by:
ExportSymbolResolution, BundleGraphExportSymbolResolution website/generate-api-docs/example.flow:843
type ExportSymbolResolution = {|
...SymbolResolution,
+exportAs: CodeSymbol | string,
|}
Referenced by:
BundleGraphBundle website/generate-api-docs/example.flow:853
A Bundle (a collection of assets)
interface Bundle {
+id: string,
+hashReference: string,
+type: string,
+env: Environment,
+filePath: ?FilePath,
+isEntry: ?boolean,
+isInline: ?boolean,
+isSplittable: ?boolean,
+target: Target,
+stats: Stats,
getEntryAssets(): Array<Asset>,
getMainEntry(): ?Asset,
getEntryAssets()
hasAsset(Asset): boolean,
traverseAssets<TContext>(visit: GraphVisitor<Asset, TContext>): ?TContext,
traverse<TContext>(visit: GraphVisitor<BundleTraversable, TContext>): ?TContext,
}
Referenced by:
NamedBundle, MutableBundleGraph, BundleGraph, Namer, Packager, PackagingProgressEvent, OptimizingProgressEventNamedBundle website/generate-api-docs/example.flow:886
A Bundle that got named by a Namer
interface NamedBundle extends Bundle {
+filePath: FilePath,
+name: string,
+displayName: string,
}
Referenced by:
Runtime, Packager, Optimizer, PackagingProgressEvent, OptimizingProgressEvent, BuildSuccessEventBundleGroup website/generate-api-docs/example.flow:896
A collection of sibling bundles (which are stored in the BundleGraph) that should be loaded together.
type BundleGroup = {|
target: Target,
entryAssetId: string,
bundleIds: Array<string>,
|}
Referenced by:
MutableBundleGraph, BundleGraphMutableBundleGraph website/generate-api-docs/example.flow:906
A BundleGraph in the Bundler that can be modified
interface MutableBundleGraph extends BundleGraph<Bundle> {
addAssetGraphToBundle(Asset, Bundle): void,
addBundleToBundleGroup(Bundle, BundleGroup): void,
createAssetReference(Dependency, Asset): 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:
CreateBundleOpts, BundlerBundleGraph website/generate-api-docs/example.flow:939
A Graph that contains Bundle-s, Asset-s, Dependency-s, BundleGroup-s
interface BundleGraph<TBundle: Bundle> {
getBundles(): Array<TBundle>,
getBundleGroupsContainingBundle(bundle: Bundle): Array<BundleGroup>,
getBundlesInBundleGroup(bundleGroup: BundleGroup): Array<TBundle>,
getChildBundles(bundle: Bundle): Array<TBundle>,
getParentBundles(bundle: Bundle): Array<TBundle>,
getSiblingBundles(bundle: Bundle): Array<TBundle>,
getReferencedBundles(bundle: Bundle): Array<TBundle>,
getDependencies(asset: Asset): Array<Dependency>,
getIncomingDependencies(asset: Asset): Array<Dependency>,
resolveExternalDependency(dependency: Dependency, bundle: ?Bundle): ?({|
type: "bundle_group",
value: BundleGroup,
|} | {|
type: "asset",
value: Asset,
|}),
isDependencyDeferred(dependency: Dependency): boolean,
getDependencyResolution(dependency: Dependency, bundle: ?Bundle): ?Asset,
findBundlesWithAsset(Asset): Array<TBundle>,
findBundlesWithDependency(Dependency): Array<TBundle>,
isAssetReachableFromBundle(asset: Asset, bundle: Bundle): boolean,
findReachableBundleWithAsset(bundle: Bundle, asset: Asset): ?TBundle,
isAssetReferenced(asset: Asset): boolean,
isAssetReferencedByDependant(bundle: Bundle, asset: Asset): boolean,
hasParentBundleOfType(bundle: Bundle, type: string): boolean,
resolveSymbol(asset: Asset, symbol: CodeSymbol, 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): Array<ExportSymbolResolution>,
traverseBundles<TContext>(visit: GraphVisitor<TBundle, TContext>, startBundle: ?Bundle): ?TContext,
}
Referenced by:
BundleGroup, MutableBundleGraph, Bundler, Namer, Runtime, Packager, BundlingProgressEvent, BuildSuccessEventBundleResult website/generate-api-docs/example.flow:1003
type BundleResult = {|
+contents: Blob,
+ast?: AST,
+map?: ?SourceMap,
|}
Referenced by:
Packager, OptimizerBundler website/generate-api-docs/example.flow:1027
Turns an asset graph into a BundleGraph.
The two methods just run in series and are functionally identitical.
type Bundler = {|
bundle({|
bundleGraph: MutableBundleGraph,
options: PluginOptions,
logger: PluginLogger,
|}): Async<void>,
optimize({|
bundleGraph: MutableBundleGraph,
options: PluginOptions,
logger: PluginLogger,
|}): Async<void>,
|}