Skip to content

bundlers/parcel

Builds an Obsidian plugin with parcel: build() and dev(), the same two entry points the esbuild builder has, producing the same main.js + styles.css + manifest.json layout.

Parcel takes no external list and no output file name, only plugins named in a .parcelrc. So the build writes a .parcelrc of its own into .parcel-cache, beside a resolver that leaves Obsidian’s modules external and resolves packages with the browser’s export conditions, a namer that names the stylesheet styles.css, a transformer that keeps dynamic imports inside main.js, and an optimizer that lets the minifier rename the bundle’s top-level bindings, and extends the consumer’s own .parcelrc when there is one (or @parcel/config-default when there is none), so every transformer the consumer configured still applies.

@parcel/core, @parcel/plugin and @parcel/config-default are optional peer dependencies, loaded only when a parcel build runs, so a plugin built with esbuild installs nothing extra.

Interface Description
BuildObsidianPluginWithParcelParams Options for buildObsidianPluginWithParcel.
BuildOptions Options for build and dev.
GetParcelConfigFilesParams Parameters for getParcelConfigFiles.
GetParcelOptionsParams Parameters for getParcelOptions.
Function Description
build Builds the Obsidian plugin in production mode using parcel.
buildObsidianPluginWithParcel Builds the Obsidian plugin with parcel, once for a production build, or watching for a development one. Runs the project’s build:compile script first when it has one, as the esbuild builder does, since parcel strips TypeScript types without checking them.
dev Builds the Obsidian plugin in development mode using parcel, watching for changes and deploying every successful rebuild into the vault.
getParcelConfigFiles Generates the files of the parcel configuration the build runs with. The build features add pipelines that run the toolkit’s shared transforms, through one generated transformer that loads them from the toolkit: Solid’s .jsx / .tsx, Svelte’s .svelte / .svelte.ts / .svelte.js, .wasm, and with styles.postcss or styles.tailwind every stylesheet, in place of parcel’s own PostCSS step. React and Preact JSX is compiled here too, since parcel reads the JSX runtime from a tsconfig without following its extends, and with any framework every script has the framework’s compile-time constants replaced. Parcel compiles Vue with @parcel/transformer-vue and scopes *.module.css itself, so those need no pipeline here.
getParcelOptions Builds the options handed to parcel’s Parcel class. The one target is electron-renderer, where Obsidian runs a plugin, and CommonJS. Parcel counts that context as both a browser and a node one: node keeps process, Buffer and process.env as Obsidian’s renderer has them, rather than polyfilled or inlined from the build machine, and browser takes a package’s browser field. Its export conditions would include node too, which the generated resolver drops. includeNodeModules bundles the dependencies, which a node-flavoured context would otherwise leave as require() calls nothing installs beside a plugin, and isLibrary keeps the entry’s default export, which is how Obsidian finds the plugin class. shouldScopeHoist is set explicitly because parcel reads it only from defaultTargetOptions for a target passed in the options, never from isLibrary as it does for one in package.json. Without it the bundle is not tree-shaken at all: Svelte’s fixture build was 224 KB with parcel against 25 KB with vite.
Type Description
ParcelConfigFiles The files of the generated parcel configuration, by file name.