-
-
Notifications
You must be signed in to change notification settings - Fork 728
feat: support sync components #2221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b727023
7d254c0
da48d40
109bd3b
d13e6a7
79823fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <template> | ||
| <p>Hello from not-content component.</p> | ||
| </template> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,8 @@ import { | |
| addComponentsDir, | ||
| addTemplate, | ||
| extendViteConfig, | ||
| installModule | ||
| installModule, | ||
| addPluginTemplate | ||
| } from '@nuxt/kit' | ||
| import { genDynamicImport, genImport, genSafeVariableName } from 'knitwork' | ||
| import type { ListenOptions } from 'listhen' | ||
|
|
@@ -20,6 +21,7 @@ import type { Lang as ShikiLang, Theme as ShikiTheme } from 'shiki-es' | |
| import { listen } from 'listhen' | ||
| import { type WatchEvent, createStorage } from 'unstorage' | ||
| import { joinURL, withLeadingSlash, withTrailingSlash } from 'ufo' | ||
| import { pascalCase } from 'scule' | ||
| import type { Component } from '@nuxt/schema' | ||
| import { name, version } from '../package.json' | ||
| import { makeIgnored } from './runtime/utils/config' | ||
|
|
@@ -58,6 +60,12 @@ export interface ModuleOptions { | |
| */ | ||
| baseURL: string | ||
| } | ||
| /** | ||
| * List the components that will be used in markdown. | ||
| * | ||
| * @default [] | ||
| */ | ||
| components: string[] | ||
| /** | ||
| * Disable content watcher and hot content reload. | ||
| * Note: Watcher is a development feature and will not includes in the production. | ||
|
|
@@ -267,6 +275,7 @@ export default defineNuxtModule<ModuleOptions>({ | |
| showURL: false | ||
| } | ||
| }, | ||
| components: [], | ||
| sources: {}, | ||
| ignores: [], | ||
| locales: [], | ||
|
|
@@ -611,6 +620,22 @@ export default defineNuxtModule<ModuleOptions>({ | |
| // @ts-ignore | ||
| await nuxt.callHook('content:context', contentContext) | ||
|
|
||
| // Add sync components to use not global components | ||
| const components = (options.components || []).map(pascalCase) | ||
|
|
||
| addPluginTemplate({ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be better if we mark these components as global instead of registering a custom plugin. Marking them as global will help other modules to list these components as global ones. Modules like
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feature is to avoid using global components and put them in the main bundle of the application actually. I want to see if this improves the performance
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, Nuxt registers lazy version of global components, but here the goal is to include it directly inside main bundle. |
||
| filename: 'plugins/content-components.ts', | ||
| getContents: () => { | ||
| return `import { defineNuxtPlugin } from '#app/nuxt' | ||
| ${genImport('#components', components)} | ||
|
|
||
| export default defineNuxtPlugin((nuxtApp) => { | ||
| ${components.map(name => `nuxtApp.vueApp.component('${name}', ${name});`).join('\n')} | ||
| }) | ||
| ` | ||
| } | ||
| }) | ||
|
|
||
| contentContext.defaultLocale = contentContext.defaultLocale || contentContext.locales[0] | ||
|
|
||
| // Generate cache integrity based on content context | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WDYT about reusing
markdown.tagsoption for this feature? We can extract all components frommarkdown.tagsmap and mark them as global.!!! This will be a bit confusing if we want to mark a component as global without changing its name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually this is a different feature than the tags itself.
We could use markdown.tags to get the extra components as synced though