diff --git a/plugins/blog/plugin-comment/src/client/components/ArtalkComment.ts b/plugins/blog/plugin-comment/src/client/components/ArtalkComment.ts index c102337bad..2653d62886 100644 --- a/plugins/blog/plugin-comment/src/client/components/ArtalkComment.ts +++ b/plugins/blog/plugin-comment/src/client/components/ArtalkComment.ts @@ -53,6 +53,8 @@ export default defineComponent({ const enableArtalk = computed(() => isString(artalkOptions.value.server)) const initArtalk = async (): Promise => { + if (__VUEPRESS_SSR__) return + const [{ default: Artalk }] = await Promise.all([ import(/* webpackChunkName: "artalk" */ 'artalk/dist/Artalk.mjs'), wait(artalkOptions.value.delay ?? 800), diff --git a/plugins/blog/plugin-comment/src/client/components/GiscusComment.ts b/plugins/blog/plugin-comment/src/client/components/GiscusComment.ts index fb94993ebf..11f68236d9 100644 --- a/plugins/blog/plugin-comment/src/client/components/GiscusComment.ts +++ b/plugins/blog/plugin-comment/src/client/components/GiscusComment.ts @@ -146,6 +146,8 @@ export default defineComponent({ ) onMounted(async () => { + if (__VUEPRESS_SSR__) return + await import(/* webpackChunkName: "giscus" */ 'giscus') loaded.value = true }) diff --git a/plugins/blog/plugin-comment/src/client/components/TwikooComment.ts b/plugins/blog/plugin-comment/src/client/components/TwikooComment.ts index 9f35122303..dfd74613df 100644 --- a/plugins/blog/plugin-comment/src/client/components/TwikooComment.ts +++ b/plugins/blog/plugin-comment/src/client/components/TwikooComment.ts @@ -29,6 +29,8 @@ export default defineComponent({ const enableTwikoo = computed(() => Boolean(twikooOptions.value.envId)) const initTwikoo = async (): Promise => { + if (__VUEPRESS_SSR__) return + const [{ init }] = await Promise.all([ import(/* webpackChunkName: "twikoo" */ 'twikoo'), wait(twikooOptions.value.delay ?? 800), diff --git a/plugins/features/plugin-photo-swipe/src/client/composables/usePhotoSwipe.ts b/plugins/features/plugin-photo-swipe/src/client/composables/usePhotoSwipe.ts index 673273e753..fbcfa3f617 100644 --- a/plugins/features/plugin-photo-swipe/src/client/composables/usePhotoSwipe.ts +++ b/plugins/features/plugin-photo-swipe/src/client/composables/usePhotoSwipe.ts @@ -119,14 +119,17 @@ export const usePhotoSwipe = ({ ) } + useEventListener('click', initPhotoSwipe, { passive: true }) + useEventListener('wheel', () => { + if (options.value.scrollToClose) photoSwipe?.close() + }) + onMounted(() => { + if (__VUEPRESS_SSR__) return + const rIC = 'requestIdleCallback' in window ? window.requestIdleCallback : setTimeout - useEventListener('click', initPhotoSwipe, { passive: true }) - useEventListener('wheel', () => { - if (options.value.scrollToClose) photoSwipe?.close() - }) rIC(() => { photoSwipeLoader = import( /* webpackChunkName: "photo-swipe" */ 'photoswipe' diff --git a/plugins/markdown/plugin-markdown-math/src/client/composables/useKatexCopy.ts b/plugins/markdown/plugin-markdown-math/src/client/composables/useKatexCopy.ts index a88c64a7ef..2247fe0352 100644 --- a/plugins/markdown/plugin-markdown-math/src/client/composables/useKatexCopy.ts +++ b/plugins/markdown/plugin-markdown-math/src/client/composables/useKatexCopy.ts @@ -2,6 +2,8 @@ import { onMounted } from 'vue' export const useKatexCopy = (): void => { onMounted(async () => { + if (__VUEPRESS_SSR__) return + await import( /* webpackChunkName: "katex" */ 'katex/dist/contrib/copy-tex.min.js' ) diff --git a/plugins/markdown/plugin-markdown-math/tsconfig.build.json b/plugins/markdown/plugin-markdown-math/tsconfig.build.json index 85b37d29a2..f7f7fe795a 100644 --- a/plugins/markdown/plugin-markdown-math/tsconfig.build.json +++ b/plugins/markdown/plugin-markdown-math/tsconfig.build.json @@ -2,7 +2,8 @@ "extends": "../../../tsconfig.build.json", "compilerOptions": { "rootDir": "./src", - "outDir": "./lib" + "outDir": "./lib", + "types": ["vuepress/client-types", "vite/client", "webpack-env"] }, "include": ["./src"], "references": [{ "path": "../../../tools/helper/tsconfig.build.json" }] diff --git a/plugins/markdown/plugin-revealjs/src/node/prepare/prepareRevealJsEntry.ts b/plugins/markdown/plugin-revealjs/src/node/prepare/prepareRevealJsEntry.ts index 08e5c8c730..01b28eb8e5 100644 --- a/plugins/markdown/plugin-revealjs/src/node/prepare/prepareRevealJsEntry.ts +++ b/plugins/markdown/plugin-revealjs/src/node/prepare/prepareRevealJsEntry.ts @@ -10,25 +10,29 @@ export const prepareRevealJsEntry = async ( await app.writeTemp( 'revealjs/index.js', `\ -export const useRevealJs = () => Promise.all([ - import(/* webpackChunkName: "reveal" */ "${getModulePath( - 'reveal.js/dist/reveal.esm.js', - import.meta, - )}").then(({ default: RevealJs }) => RevealJs), - import(/* webpackChunkName: "reveal" */ "${getModulePath( - 'reveal.js/plugin/markdown/markdown.esm.js', - import.meta, - )}").then(({ default: plugin }) => plugin), -${revealPlugins - .map( - (plugin) => - ` import(/* webpackChunkName: "reveal" */ "${getModulePath( - `reveal.js/plugin/${plugin}/${plugin}.esm.js`, - import.meta, - )}").then(({ default: plugin }) => plugin)`, - ) - .join(',\n')} -]); +export const useRevealJs = () => Promise.all( + __VUEPRESS_SSR__ + ? [] + : [ + import(/* webpackChunkName: "reveal" */ "${getModulePath( + 'reveal.js/dist/reveal.esm.js', + import.meta, + )}").then(({ default: RevealJs }) => RevealJs), + import(/* webpackChunkName: "reveal" */ "${getModulePath( + 'reveal.js/plugin/markdown/markdown.esm.js', + import.meta, + )}").then(({ default: plugin }) => plugin), + ${revealPlugins + .map( + (plugin) => + ` import(/* webpackChunkName: "reveal" */ "${getModulePath( + `reveal.js/plugin/${plugin}/${plugin}.esm.js`, + import.meta, + )}").then(({ default: plugin }) => plugin)`, + ) + .join(',\n')} + ] + ); `, ) } diff --git a/plugins/search/plugin-docsearch/src/client/components/DocSearch.ts b/plugins/search/plugin-docsearch/src/client/components/DocSearch.ts index b9bf616be1..31c44f7572 100644 --- a/plugins/search/plugin-docsearch/src/client/components/DocSearch.ts +++ b/plugins/search/plugin-docsearch/src/client/components/DocSearch.ts @@ -53,6 +53,8 @@ export const DocSearch = defineComponent({ * Import docsearch js and initialize */ const initialize = async (): Promise => { + if (__VUEPRESS_SSR__) return + const { default: docsearch } = await import('@docsearch/js') const { searchParameters } = options.value