bundlers/vite
Builds an Obsidian plugin with vite: a vite plugin that turns vite build into a library build of src/main.ts with the same main.js + styles.css + manifest.json layout the esbuild builder produces, deploys a vite build --watch build into the vault, and fills in only the options the consumer’s own vite.config leaves unset.
vite is an optional peer dependency and this module only imports its types, so a plugin built with esbuild installs nothing extra.
Interfaces
Section titled “Interfaces”| Interface | Description |
|---|---|
| GetViteFeatureConfigParams | Parameters for getViteFeatureConfig. |
| ObsidianPluginViteOptions | Options for obsidianPluginVite. |
Functions
Section titled “Functions”| Function | Description |
|---|---|
| getViteBuildMode | Decides the build mode of a vite build from the consumer’s config: development for a watch build or for --mode development, production otherwise. |
| getViteConfigDefaults | Builds the part of the vite config the plugin contributes: only the options the consumer left unset. |
| getViteFeatureConfig | Builds the part of the vite config the build features contribute, each only where the consumer’s config left it unset: the framework’s compile-time constants (define), the automatic JSX runtime for React and Preact (oxc.jsx), and the PostCSS plugins of the styles option (css.postcss). |
| obsidianPluginVite | Creates a vite plugin that builds an Obsidian plugin. What it does, each only when the consumer’s config has not said otherwise: - build.lib builds src/main.ts as one CommonJS main.js, with its CSS in styles.css. - build.outDir is dist/build (dist/dev in development). - build.minify is on in production only, and build.sourcemap is inline in development only. - Every asset is inlined, because an Obsidian release ships main.js and styles.css and nothing else. - Dynamic imports are inlined into main.js, and the generated-file banner heads it. And always: Obsidian’s own modules (obsidian, electron, CodeMirror, Lezer) and the Node builtins are external beside the consumer’s own external, the output folder is emptied once before the first write (build.emptyOutDir is turned off, since this plugin does it), every emitted CSS file ends up in styles.css, manifest.json (and in development .hotreload) is copied beside it, and a development build is deployed into the vault named by OBSIDIAN_CONFIG_FOLDER. The build features (ObsidianPluginFeatureOptions): - framework: 'react' | 'preact' sets oxc.jsx to the automatic runtime (unless set). - framework: 'solid' | 'svelte' compiles the components with the toolkit’s shared transforms, and 'vue' adds unplugin-vue. - Any framework defines process.env.NODE_ENV (and Vue’s feature flags), which a library build leaves alone. - styles.postcss and styles.tailwind set css.postcss (unless set); vite scopes *.module.css itself, so styles.cssModules changes nothing here. - wasm imports a .wasm module as its bytes. |