it actually works!

pull/3478/head
Jacob Hummer 3 years ago committed by GitHub
parent 690ba9b8d9
commit dd326ded38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -84,10 +84,21 @@ const sidebar: DefaultTheme.Config['sidebar'] = {
}
export default defineConfig({
vite: {
plugins: [
{
name: 'example',
configResolved(config) {
console.dir(config, { depth: 10 })
}
}
]
},
extends: [
{
title: 'Example',
description: 'An example app using VitePress.'
description: 'An example app using VitePress.',
additionalThemeFiles: ['./my-additional-theme-file.ts']
},
{
themeConfig: {

@ -0,0 +1,7 @@
import type { Theme } from 'vitepress'
export default {
enhanceApp({ app }) {
console.log('enhanceApp from my-additional-theme-file.ts')
}
} satisfies Theme

@ -1,5 +1,5 @@
import RawTheme from '@theme/index'
import SiteConfigThemes from '@theme/site-config-themes'
import SiteConfigThemes from '@site-config-themes'
import {
createApp as createClientApp,
createSSRApp,

@ -23,7 +23,7 @@ declare module '@theme/index' {
export default theme
}
declare module '@theme/site-config-themes' {
declare module '@site-config-themes' {
import type { Theme } from 'vitepress'
const themes: Theme[]
export default themes

@ -1,8 +1,9 @@
import { createRequire } from 'module'
import { resolve, join } from 'path'
import { fileURLToPath, pathToFileURL } from 'url'
import { fileURLToPath } from 'url'
import type { Alias, AliasOptions } from 'vite'
import type { SiteConfig } from './config'
import fs from 'fs-extra'
const require = createRequire(import.meta.url)
const PKG_ROOT = resolve(fileURLToPath(import.meta.url), '../..')
@ -27,16 +28,17 @@ export function resolveAliases(
const { root, themeDir } = siteConfig
const siteConfigThemesJS = `\
${siteConfig.additionalThemeFiles
.map((f, i) => `import $${i} from ${JSON.stringify(pathToFileURL(f))}`)
.map((f, i) => `import $${i} from ${JSON.stringify(f)}`)
.join('\n')}
export default [${siteConfig.additionalThemeFiles
.map((f, i) => `$${i}`)
.join(', ')}]`
const tmpfile = join(siteConfig.cacheDir, 'site-config-themes.ts')
fs.writeFileSync(tmpfile, siteConfigThemesJS)
const paths: Record<string, string> = {
'@theme': themeDir,
'@theme/site-config-themes': `data:text/javascript,${encodeURIComponent(
siteConfigThemesJS
)}`,
'@site-config-themes': tmpfile,
[SITE_DATA_ID]: SITE_DATA_REQUEST_PATH
}

@ -1,15 +1,13 @@
import _debug from 'debug'
import fs from 'fs-extra'
import path from 'path'
import url from 'url'
import c from 'picocolors'
import {
createLogger,
loadConfigFromFile,
mergeConfig as mergeViteConfig,
normalizePath,
type ConfigEnv,
type ResolvedConfig
type ConfigEnv
} from 'vite'
import { DEFAULT_THEME_PATH } from './alias'
import { resolvePages } from './plugins/dynamicRoutesPlugin'
@ -277,8 +275,8 @@ function resolveSiteDataHead(userConfig?: UserConfig): HeadConfig[] {
typeof userConfig?.appearance === 'string'
? userConfig?.appearance
: typeof userConfig?.appearance === 'object'
? userConfig.appearance.initialValue ?? 'auto'
: 'auto'
? userConfig.appearance.initialValue ?? 'auto'
: 'auto'
head.push([
'script',

Loading…
Cancel
Save