Externalize @codemirror/state and @codemirror/view from the bundle

Obsidian ships CodeMirror in its runtime; bundling our own copy is
both wasteful (~200 kB) and risky (two CM6 instances in the host).
The bundling-by-default also broke pnpm installs because pnpm doesn't
hoist devDependencies the way npm does, so Rollup couldn't resolve
the import paths.

Externalising drops the plugin back to ~620 kB and matches the
recommended pattern for Obsidian plugins that use CM6.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Mike Thicke 2026-05-30 23:08:58 -04:00
parent 1cc9edf63c
commit dbf4f2e96f

View file

@ -34,7 +34,14 @@ export default defineConfig({
fileName: () => "main.js",
},
rollupOptions: {
external: ["obsidian", "electron"], // don't bundle the host libs
// Obsidian's runtime already loads CodeMirror; importing it as a peer
// keeps our bundle small and avoids two CM6 instances in the host.
external: [
"obsidian",
"electron",
"@codemirror/state",
"@codemirror/view",
],
output: {
exports: "named",
assetFileNames: () => "styles.css", // Always output CSS as styles.css