From e69df93d5acacefa217c46e3db80a2d188bcd390 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Mon, 16 Nov 2026 18:49:44 +0000 Subject: [PATCH] fix(vue): register Nuxt components from their own entries The Nuxt module registered and from the package index, which also imports the parser behind . Pages that only render a parsed document with shipped the parser (markdown-exit, js-yaml, linkify-it) anyway. Amp-Thread-ID: https://ampcode.com/threads/T-01a1e525-9983-7071-a70a-d5ef82f1ba95 --- AGENTS.md | 2 +- packages/comark-vue/src/nuxt.ts | 4 +++- packages/comark-vue/test/nuxt.test.ts | 31 +++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 packages/comark-vue/test/nuxt.test.ts diff --git a/AGENTS.md b/AGENTS.md index 02194bff..b94ffe9a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -276,7 +276,7 @@ import math, { Math } from '@comark/vue/plugins/math' import mermaid, { Mermaid } from '@comark/vue/plugins/mermaid' ``` -`@comark/vue/nuxt` is the Nuxt module: `modules: ['@comark/vue']` loads it because Nuxt tries the `/nuxt` subpath first. It auto-imports `Markdown`, `MarkdownDocument`, `defineMarkdownComponent` and `defineMarkdownDocumentComponent`, plus `parseMarkdown` and `createMarkdownParser` in the app and in server routes (from `@comark/vue/parse`), turns on Nuxt UI prose components, and adds the `@comark/vue/vite` plugin with `prose: false`. It does not register `~/components/prose`. `@nuxt/kit` and `@nuxt/schema` are optional peer dependencies. +`@comark/vue/nuxt` is the Nuxt module: `modules: ['@comark/vue']` loads it because Nuxt tries the `/nuxt` subpath first. It auto-imports `Markdown` and `MarkdownDocument` (each from `@comark/vue/components/*`, so `` alone never bundles the parser), `defineMarkdownComponent` and `defineMarkdownDocumentComponent`, plus `parseMarkdown` and `createMarkdownParser` in the app and in server routes (from `@comark/vue/parse`), turns on Nuxt UI prose components, and adds the `@comark/vue/vite` plugin with `prose: false`. It does not register `~/components/prose`. `@nuxt/kit` and `@nuxt/schema` are optional peer dependencies. ## Package: @comark/react diff --git a/packages/comark-vue/src/nuxt.ts b/packages/comark-vue/src/nuxt.ts index 9ed1f1c4..889c09c8 100644 --- a/packages/comark-vue/src/nuxt.ts +++ b/packages/comark-vue/src/nuxt.ts @@ -34,8 +34,10 @@ export default defineNuxtModule({ if (installed) installed.entryPath = '@comark/vue/nuxt' }) + // From each component's own entry, not the package index: the index also loads `` and its + // parser, which would land in every bundle that only renders a parsed document with ``. for (const name of ['Markdown', 'MarkdownDocument']) { - addComponent({ name, export: name, filePath: '@comark/vue', priority: 1 }) + addComponent({ name, export: name, filePath: `@comark/vue/components/${name}`, priority: 1 }) } addImports( diff --git a/packages/comark-vue/test/nuxt.test.ts b/packages/comark-vue/test/nuxt.test.ts new file mode 100644 index 00000000..429bad81 --- /dev/null +++ b/packages/comark-vue/test/nuxt.test.ts @@ -0,0 +1,31 @@ +import { describe, expect, it, vi } from 'vitest' +import { Markdown, MarkdownDocument } from '@comark/vue' + +const components = vi.hoisted(() => [] as Array<{ name: string; export: string; filePath: string }>) + +vi.mock('@nuxt/kit', () => ({ + defineNuxtModule: (definition: unknown) => definition, + addComponent: (component: (typeof components)[number]) => components.push(component), + addImports: () => {}, + addServerImports: () => {}, + addVitePlugin: () => {}, +})) + +describe('@comark/vue nuxt module', () => { + it('registers each component from its own entry, so does not load the parser', async () => { + const { default: module } = (await import('../src/nuxt.ts')) as any + module.setup({}, { hook: () => {}, options: {} }) + + expect(components.map((c) => [c.name, c.filePath])).toEqual([ + ['Markdown', '@comark/vue/components/Markdown'], + ['MarkdownDocument', '@comark/vue/components/MarkdownDocument'], + ]) + + // Each entry exports the same component as the package index. + const fromIndex: Record = { Markdown, MarkdownDocument } + for (const component of components) { + const entry = await import(component.filePath) + expect(entry[component.export]).toBe(fromIndex[component.name]) + } + }) +})