|
|
|
@ -1,9 +1,7 @@
|
|
|
|
|
import { createRequire } from 'module'
|
|
|
|
|
import { resolve, join } from 'path'
|
|
|
|
|
import { fileURLToPath } from 'url'
|
|
|
|
|
import { Alias, AliasOptions } from 'vite'
|
|
|
|
|
|
|
|
|
|
const require = createRequire(import.meta.url)
|
|
|
|
|
const PKG_ROOT = resolve(fileURLToPath(import.meta.url), '../..')
|
|
|
|
|
|
|
|
|
|
export const DIST_CLIENT_PATH = resolve(PKG_ROOT, 'client')
|
|
|
|
@ -17,8 +15,6 @@ export const DEFAULT_THEME_PATH = join(DIST_CLIENT_PATH, 'theme-default')
|
|
|
|
|
export const SITE_DATA_ID = '@siteData'
|
|
|
|
|
export const SITE_DATA_REQUEST_PATH = '/' + SITE_DATA_ID
|
|
|
|
|
|
|
|
|
|
const vueRuntimePath = 'vue/dist/vue.runtime.esm-bundler.js'
|
|
|
|
|
|
|
|
|
|
export function resolveAliases(root: string, themeDir: string): AliasOptions {
|
|
|
|
|
const paths: Record<string, string> = {
|
|
|
|
|
'/@theme': themeDir,
|
|
|
|
@ -26,15 +22,6 @@ export function resolveAliases(root: string, themeDir: string): AliasOptions {
|
|
|
|
|
[SITE_DATA_ID]: SITE_DATA_REQUEST_PATH
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// prioritize vue installed in project root and fallback to
|
|
|
|
|
// vue that comes with vitepress itself.
|
|
|
|
|
let vuePath
|
|
|
|
|
try {
|
|
|
|
|
vuePath = require.resolve(vueRuntimePath, { paths: [root] })
|
|
|
|
|
} catch (e) {
|
|
|
|
|
vuePath = require.resolve(vueRuntimePath)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const aliases: Alias[] = [
|
|
|
|
|
...Object.keys(paths).map((p) => ({
|
|
|
|
|
find: p,
|
|
|
|
@ -52,12 +39,6 @@ export function resolveAliases(root: string, themeDir: string): AliasOptions {
|
|
|
|
|
{
|
|
|
|
|
find: /^vitepress\//,
|
|
|
|
|
replacement: PKG_ROOT + '/'
|
|
|
|
|
},
|
|
|
|
|
// make sure it always use the same vue dependency that comes
|
|
|
|
|
// with vitepress itself
|
|
|
|
|
{
|
|
|
|
|
find: /^vue$/,
|
|
|
|
|
replacement: vuePath
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|