From 196974474edfab0d0846e1f1ec1c1d01d1388b32 Mon Sep 17 00:00:00 2001 From: sapphi-red <49056869+sapphi-red@users.noreply.github.com> Date: Fri, 3 Nov 2023 15:13:04 +0900 Subject: [PATCH] fix: add ?import for vite-ignore import for md files --- src/client/app/utils.ts | 2 +- src/client/shim.d.ts | 1 + src/node/plugin.ts | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/client/app/utils.ts b/src/client/app/utils.ts index 5028483c4b80..98fab8861ff4 100644 --- a/src/client/app/utils.ts +++ b/src/client/app/utils.ts @@ -40,7 +40,7 @@ export function pathToFile(path: string) { pagePath = pagePath.replace(/\/$/, '/index') // /foo/ -> /foo/index if (import.meta.env.DEV) { // always force re-fetch content in dev - pagePath += `.md?t=${Date.now()}` + pagePath += `.md?${__IS_VITE_4__ ? '' : 'import&'}t=${Date.now()}` } else { // in production, each .md file is built into a .md.js file following // the path conversion scheme. diff --git a/src/client/shim.d.ts b/src/client/shim.d.ts index e12889d5d2db..43b93df141e3 100644 --- a/src/client/shim.d.ts +++ b/src/client/shim.d.ts @@ -4,6 +4,7 @@ declare const __ALGOLIA__: boolean declare const __CARBON__: boolean declare const __VUE_PROD_DEVTOOLS__: boolean declare const __ASSETS_DIR__: string +declare const __IS_VITE_4__: boolean declare module '*.vue' { import type { DefineComponent } from 'vue' diff --git a/src/node/plugin.ts b/src/node/plugin.ts index 6de976ec48c8..e4612bd63eb2 100644 --- a/src/node/plugin.ts +++ b/src/node/plugin.ts @@ -3,6 +3,7 @@ import c from 'picocolors' import { mergeConfig, searchForWorkspaceRoot, + version, type ModuleNode, type Plugin, type ResolvedConfig, @@ -153,7 +154,8 @@ export async function createVitePressPlugin( site.themeConfig?.search?.provider === 'algolia' || !!site.themeConfig?.algolia, // legacy __CARBON__: !!site.themeConfig?.carbonAds, - __ASSETS_DIR__: JSON.stringify(siteConfig.assetsDir) + __ASSETS_DIR__: JSON.stringify(siteConfig.assetsDir), + __IS_VITE_4__: version.split('.')[0] === '4' }, optimizeDeps: { // force include vue to avoid duplicated copies when linked + optimized