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]) + } + }) +})