import path from 'path' ; import { Alias , AliasOptions } from 'vite' ; const PKG_ROOT = path . join ( __dirname , '../../' ) ; export const DIST_CLIENT_PATH = path . join ( __dirname , '../client' ) ; export const APP_PATH = path . join ( DIST_CLIENT_PATH , 'app' ) ; export const SHARED_PATH = path . join ( DIST_CLIENT_PATH , 'shared' ) ; export const DEFAULT_THEME_PATH = 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 , themeDir ) { const paths = { '/@theme' : themeDir , '/@shared' : SHARED_PATH , [ SITE_DATA_ID ] : SITE_DATA_REQUEST_PATH } ; let vuePath ; try { vuePath = require . resolve ( vueRuntimePath , { paths : [ root ] } ) ; } catch ( e ) { vuePath = require . resolve ( vueRuntimePath ) ; } const aliases = [ ... Object . keys ( paths ) . map ( ( p ) => ( { find : p , replacement : paths [ p ] } ) ) , { find : /^vitepress$/ , replacement : path . join ( __dirname , '../client/index' ) } , { find : /^vitepress\/theme$/ , replacement : path . join ( __dirname , '../client/theme-default/index' ) } , { find : /^vitepress\// , replacement : PKG_ROOT + '/' } , { find : /^vue$/ , replacement : vuePath } ] ; return aliases ; }