Skip to content
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

fix(build): do not register web-socket plugin on non-dev env #1768

Merged
merged 1 commit into from
Dec 21, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 4 additions & 24 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,6 @@ export default defineNuxtModule<ModuleOptions>({
)
})

// Add Content plugin
addPlugin(resolveRuntimeModule('./plugins/ws'))

nuxt.hook('nitro:config', (nitroConfig) => {
// Init Nitro context
nitroConfig.prerender = nitroConfig.prerender || {}
Expand Down Expand Up @@ -541,27 +538,6 @@ export default defineNuxtModule<ModuleOptions>({
])
}

// Register anchor link generation
if (options.markdown.anchorLinks === true) {
options.markdown.anchorLinks = {
depth: 6,
exclude: []
}
} else if (options.markdown.anchorLinks === false) {
options.markdown.anchorLinks = {
depth: 0,
exclude: []
}
} else {
options.markdown.anchorLinks = {
...{
depth: 4,
exclude: [1]
},
...options.markdown.anchorLinks
}
}

// @ts-ignore
await nuxt.callHook('content:context', contentContext)

Expand Down Expand Up @@ -651,6 +627,10 @@ export default defineNuxtModule<ModuleOptions>({
})
return
}
// ~~ DEV ~~ //

// Add Content plugin
addPlugin(resolveRuntimeModule('./plugins/ws'))

nuxt.hook('nitro:init', async (nitro) => {
if (!options.watch || !options.watch.ws) { return }
Expand Down
6 changes: 6 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,14 @@ export function createWebSocket () {
}

export function processMarkdownOptions (options: ModuleOptions['markdown']) {
// Refine anchor link generation
const anchorLinks = typeof options.anchorLinks === 'boolean'
? { depth: options.anchorLinks ? 6 : 0, exclude: [] }
: { depth: 4, exclude: [1], ...options.anchorLinks }

return {
...options,
anchorLinks,
remarkPlugins: resolveMarkdownPlugins(options.remarkPlugins),
rehypePlugins: resolveMarkdownPlugins(options.rehypePlugins)
}
Expand Down