Skip to content

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.

Import:

import { obsidianPluginVite } from '@mnaoumov/obsidian-dev-toolkit/bundlers/vite';

Signature:

function obsidianPluginVite(options: ObsidianPluginViteOptions): PluginOption[]

Parameters:

Parameter Type Description
options ObsidianPluginViteOptions The ObsidianPluginViteOptions.

Returns: PluginOption[] — The vite plugins, which vite takes as one entry of its plugins.


Links to this page: