Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<MarkdownDocument>` 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

Expand Down
4 changes: 3 additions & 1 deletion packages/comark-vue/src/nuxt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ export default defineNuxtModule<ComarkModuleOptions>({
if (installed) installed.entryPath = '@comark/vue/nuxt'
})

// From each component's own entry, not the package index: the index also loads `<Markdown>` and its
// parser, which would land in every bundle that only renders a parsed document with `<MarkdownDocument>`.
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(
Expand Down
31 changes: 31 additions & 0 deletions packages/comark-vue/test/nuxt.test.ts
Original file line number Diff line number Diff line change
@@ -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 <MarkdownDocument> 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<string, unknown> = { Markdown, MarkdownDocument }
for (const component of components) {
const entry = await import(component.filePath)
expect(entry[component.export]).toBe(fromIndex[component.name])
}
})
})
Loading