'\n\n html.value = await codeToHtml(code, {\n lang: 'vue',\n theme: 'material-theme-ocean',\n })\n})\n\u003C/script>\n\n\u003Ctemplate>\n \u003Cdiv v-html=\"html\">\u003C/div>\n\u003C/template>\n```\n5. Put this code into a `.md` file:\n```md\n---\nlayout: page\nsidebar: false\n---\n\n\u003Cscript setup>\nimport CustomComponent from './CustomComponent.vue'\n\u003C/script>\n\n\u003CCustomComponent />\n```\n5. `pnpm build && pnpm docs:build`\n6. `pnpm preview`\n - Open the page where the Shiki is used.\n - Open DevTools → Network tab.\n - Notice that only the Vue grammar and material-theme-ocean chunks are fetched. This is correct. ✅\n7. `pnpm docs:preview`\n- Open the page where the Shiki is used.\n- Open DevTools → Network tab.\n- Notice that all Shiki languages and themes (even those not in use) are fetched at page load. This is incorrect. ❌\n\n### Expected behavior\n\nWhen building VitePress production site with `pnpm docs:build`, the output should behave like a standard Vue production build (`pnpm build`) when using libraries such as Shiki: the production page should not fetch every chunk up front at page load; it should only fetch the chunks when they are needed.\n\n### System Info\n\n```Text\nSystem:\n OS: Windows 11 10.0.26100\n CPU: (20) x64 12th Gen Intel(R) Core(TM) i7-12700H\n Memory: 33.51 GB / 63.67 GB\n Binaries:\n Node: 22.11.0 - C:\\Program Files\\nodejs\\node.EXE\n Yarn: 1.22.22 - ~\\AppData\\Roaming\\npm\\yarn.CMD\n npm: 11.4.1 - C:\\Program Files\\nodejs\\npm.CMD\n pnpm: 10.11.0 - ~\\AppData\\Local\\pnpm\\pnpm.EXE\n Browsers:\n Edge: Chromium (130.0.2849.80)\n npmPackages:\n vitepress: ^1.6.3 => 1.6.3\n```\n\n### Additional context\n\n_No response_\n\n### Validations\n\n- [x] Check if you're on the [latest VitePress version](https://github.com/vuejs/vitepress/releases/latest).\n- [x] Follow our [Code of Conduct](https://vuejs.org/about/coc.html)\n- [x] Read the [docs](https://vitepress.dev).\n- [x] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.",[2948],{"name":2908,"color":2909},4770,"VitePress build eagerly loads all Shiki chunks instead of lazy-loading only what's needed","2025-06-03T04:11:18Z","https://github.com/vuejs/vitepress/issues/4770",0.716703,{"description":2955,"labels":2956,"number":2957,"owner":2866,"repository":2867,"state":2868,"title":2958,"updated_at":2959,"url":2960,"score":2961},"### Is your feature request related to a problem? Please describe.\r\n\r\n许多第三方库会在导入时的顶层代码中访问 `window` 或者 `document`\r\n我不可能在第三库的源码中加上条件判断,这是不切实际的。\r\n\r\n假设有一个Vue插件模块名字就叫 \"a-vue-plugin\",并且假设它提供了大量有用的Vue组件或者实用功能。\r\n```typescript\r\nwindow.ABC = 123 // 这个模块在代码顶层就访问里 window\r\n\r\nconst plugin = {\r\n // ...\r\n}\r\n\r\nexport default plugin\r\n```\r\n\r\ndocs/.vitepress/theme/index.ts\r\n```typescript\r\n// ...\r\nimport { plugin } from 'a-vue-plugin''\r\n\r\nexport default define\u003CTheme>({\r\n NotFound,\r\n Layout: VPApp,\r\n enhanceApp: ({ app }) => {\r\n // 这样写显然是无济于事的,因为在执行 import { plugin } from 'a-vue-plugin' 时就已经访问到 window 了 \r\n if (!import.meta.env.SSR) {\r\n app.use(plugin) // 这里需要使用这个插件\r\n }\r\n },\r\n})\r\n```\r\n最终抛出错误\r\n```\r\n⠋ rendering pages...ReferenceError: window is not defined\r\n```\r\n\r\n### Describe the solution you'd like\r\n\r\n目前缺少完全合理的解决方案,请求官方针对此问题提供标准的解决方案或者规避方案。\r\n\r\n### Describe alternatives you've considered\r\n\r\n这是一个可能的解决方案,但需要 enhanceApp 支持异步才行。\r\n```typescript\r\nexport default define\u003CTheme>({\r\n NotFound,\r\n Layout: VPApp,\r\n enhanceApp: async ({ app }) => {\r\n if (!import.meta.env.SSR) {\r\n const plugin = (await import('a-vue-plugin')).default\r\n app.use(plugin)\r\n }\r\n },\r\n})\r\n```\r\n\r\n### Additional context\r\n\r\n类似的问题 [#](https://github.com/vuejs/vitepress/issues/1727#issue-1507239476)\r\n\r\n### Validations\r\n\r\n- [X] Follow our [Code of Conduct](https://vuejs.org/about/coc.html)\r\n- [X] Read the [docs](https://vitepress.vuejs.org).\r\n- [X] Read the [Contributing Guidelines](https://github.com/vuejs/vitepress/blob/main/.github/contributing.md).\r\n- [X] Check that there isn't already an issue that asks for the same feature to avoid creating a duplicate.",[],1884,"如何针对静态导入跳过SSR?","2023-03-23T00:04:27Z","https://github.com/vuejs/vitepress/issues/1884",0.7177641,["Reactive",2963],{},["Set"],["ShallowReactive",2966],{"$fTRc1wZytZ_XrK4EfJfei_Sz-An4H4Yy6syhVxH_PVJc":-1,"$fIrh29oGjtvJvZnAH5fRJ5hvMIkNpNkcT47V7YkDFxjw":-1},"/vuejs/vitepress/356"]