diff --git a/src/client/enhance.ts b/src/client/enhance.ts index 6bed7b2..0b81337 100644 --- a/src/client/enhance.ts +++ b/src/client/enhance.ts @@ -4,6 +4,5 @@ import Mermaid from './Mermaid' export default defineClientAppEnhance(({ app }) => { if (!__VUEPRESS_SSR__) { customElements.define('h-mermaid', Mermaid) - app.config.compilerOptions.isCustomElement = tag => tag.startsWith('h-') } }) diff --git a/src/node/index.ts b/src/node/index.ts index f381ef0..c684eb2 100644 --- a/src/node/index.ts +++ b/src/node/index.ts @@ -7,5 +7,29 @@ export default (opt: Record = {}) => ({ extendsMarkdown: (md: any) => { md.__mermaidConfig = opt md.use(MermaidPlugin) + }, + extendsBundlerOptions: (bundlerOptions, app) => { + // 修改 @vuepress/bundler-vite 的配置项 + if (app.options.bundler.name === '@vuepress/bundler-vite') { + bundlerOptions.vuePluginOptions ??= {} + bundlerOptions.vuePluginOptions.template ??= {} + bundlerOptions.vuePluginOptions.template.compilerOptions ??= {} + const isCustomElement = bundlerOptions.vuePluginOptions.template.compilerOptions.isCustomElement + bundlerOptions.vuePluginOptions.template.compilerOptions.isCustomElement = (tag) => { + if (isCustomElement?.(tag)) return true + if (tag === 'h-mermaid') return true + } + } + + // 修改 @vuepress/bundler-webpack 的配置项 + if (app.options.bundler.name === '@vuepress/bundler-webpack') { + bundlerOptions.vue ??= {} + bundlerOptions.vue.compilerOptions ??= {} + const isCustomElement = bundlerOptions.vue.compilerOptions.isCustomElement + bundlerOptions.vue.compilerOptions.isCustomElement = (tag) => { + if (isCustomElement?.(tag)) return true + if (tag === 'h-mermaid') return true + } + } } })