Skip to content

bundlers/obsidian-plugin-features

The build features every bundler adapter offers beside the plain plugin build: a UI framework, the stylesheet pipeline and WebAssembly. Every adapter takes the same ObsidianPluginFeatureOptions, so a project that switches bundler keeps its options and its installed packages.

Each feature’s packages are optional peer dependencies of the toolkit, imported from the PROJECT’s own node_modules only when the feature is on, through importOptionalPeer.

Erasable TypeScript only (no enums, no parameter properties): obsidian-plugin-transforms.ts imports this module, and a webpack loader or a parcel worker loads that one straight from source when the toolkit runs from source.

Interface Description
GetFrameworkDefinesParams Parameters for getFrameworkDefines.
ImportOptionalPeerParams Parameters for importOptionalPeer.
ObsidianPluginFeatureOptions The build features beside the plain plugin build. Every option is off unless set.
ObsidianPluginStylesOptions The stylesheet pipeline of ObsidianPluginFeatureOptions.
Function Description
getFeatureFileKind Tells which shared transform a module of a rollup-family build goes through, by its id. A virtual module (an id starting with \0) goes through none. A query is part of the match for a stylesheet, so a Vue component’s ?vue&type=style&lang.css block counts as one, and is cut off for the rest.
getFrameworkDefines Builds the compile-time constants a framework’s runtime reads, which Obsidian’s renderer does not define. process.env.NODE_ENV picks a runtime’s production build (React, Preact’s devtools, Vue, Solid), and without it a production plugin would bundle and run the development one. Vue also reads its three feature flags.
getJsxImportSource Tells which package supplies the automatic JSX runtime of a framework.
importOptionalPeer Imports an optional peer dependency from the project’s own node_modules. Resolved from the project rather than from the toolkit, so a package manager that does not hoist still finds what the project installed.
isCssModuleFile Tells whether a stylesheet is a CSS module by its file name.
isPostcssNeeded Tells whether a stylesheet goes through PostCSS at all.
replaceDefines Replaces each compile-time constant in a module’s code with its value, as a bundler’s define does: only where the whole expression stands on its own, so process.env.NODE_ENV is replaced and a.process.env.NODE_ENV or process.env.NODE_ENV_X are not.
requireOptionalPeer Loads an optional peer dependency from the project’s own node_modules synchronously, for a bundler whose plugins are applied synchronously (webpack). Loads an ES module too, through require.
resolveOptionalPeer Resolves an optional peer dependency from the project’s own node_modules.
Type Description
FeatureFileKind Which shared transform a module goes through, as getFeatureFileKind tells it.
ObsidianPluginFramework A UI framework the bundler adapters compile. - react and preact compile JSX with the automatic runtime from react / preact. - solid compiles JSX with babel-preset-solid. - svelte compiles .svelte components and .svelte.ts / .svelte.js modules with the project’s svelte. - vue compiles single-file components with unplugin-vue (on parcel, with @parcel/transformer-vue).
RequireOptionalPeerParams Parameters for requireOptionalPeer: the same as ImportOptionalPeerParams.
ResolveOptionalPeerParams Parameters for resolveOptionalPeer: the same as ImportOptionalPeerParams.