From 04701280ef1f15e9b6d8965a47508ad7177d2947 Mon Sep 17 00:00:00 2001 From: Ahad Birang Date: Wed, 21 Dec 2022 12:37:27 +0100 Subject: [PATCH] fix(build): do not register web-socket plugin on non-dev env --- src/module.ts | 28 ++++------------------------ src/utils.ts | 6 ++++++ 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/src/module.ts b/src/module.ts index f7244128b..d4356baeb 100644 --- a/src/module.ts +++ b/src/module.ts @@ -307,9 +307,6 @@ export default defineNuxtModule({ ) }) - // Add Content plugin - addPlugin(resolveRuntimeModule('./plugins/ws')) - nuxt.hook('nitro:config', (nitroConfig) => { // Init Nitro context nitroConfig.prerender = nitroConfig.prerender || {} @@ -541,27 +538,6 @@ export default defineNuxtModule({ ]) } - // 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) @@ -651,6 +627,10 @@ export default defineNuxtModule({ }) return } + // ~~ DEV ~~ // + + // Add Content plugin + addPlugin(resolveRuntimeModule('./plugins/ws')) nuxt.hook('nitro:init', async (nitro) => { if (!options.watch || !options.watch.ws) { return } diff --git a/src/utils.ts b/src/utils.ts index 0d419372d..63a204567 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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) }