feat: add window.__VITEPRESS__

pull/3634/head
Lo 2 years ago
parent 90eab25b70
commit f88aa8db01

@ -17,6 +17,7 @@ import { usePrefetch } from './composables/preFetch'
import { dataSymbol, initData, siteDataRef, useData } from './data'
import { RouterSymbol, createRouter, scrollTo, type Router } from './router'
import { inBrowser, pathToFile } from './utils'
import { getGlobalThis } from '../shared'
function resolveThemeExtends(theme: typeof RawTheme): typeof RawTheme {
if (theme.extends) {
@ -64,6 +65,9 @@ const VitePressApp = defineComponent({
})
export async function createApp() {
const target = getGlobalThis()
target.__VITEPRESS__ = true
const router = newRouter()
const app = newApp()

@ -211,3 +211,20 @@ export function treatAsHtml(filename: string): boolean {
export function escapeRegExp(str: string) {
return str.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d')
}
let _globalThis: any
export const getGlobalThis = (): any => {
return (
_globalThis ||
(_globalThis =
typeof globalThis !== 'undefined'
? globalThis
: typeof self !== 'undefined'
? self
: typeof window !== 'undefined'
? window
: typeof global !== 'undefined'
? global
: {})
)
}

Loading…
Cancel
Save