diff --git a/src/node/alias.ts b/src/node/alias.ts index bb2314c20c91..cc338f5e6d58 100644 --- a/src/node/alias.ts +++ b/src/node/alias.ts @@ -22,7 +22,6 @@ export function resolveAliases( userConfig: UserConfig ): AliasOptions { const paths: Record = { - ...userConfig.alias, '/@theme': themeDir, '/@shared': SHARED_PATH, [SITE_DATA_ID]: SITE_DATA_REQUEST_PATH diff --git a/src/node/config.ts b/src/node/config.ts index 4281e0538c14..93f4574dbb6b 100644 --- a/src/node/config.ts +++ b/src/node/config.ts @@ -2,7 +2,7 @@ import path from 'path' import fs from 'fs-extra' import chalk from 'chalk' import globby from 'globby' -import { AliasOptions } from 'vite' +import { AliasOptions, UserConfig as ViteConfig } from 'vite' import { Options as VuePluginOptions } from '@vitejs/plugin-vue' import { SiteData, HeadConfig, LocaleConfig } from './shared' import { resolveAliases, APP_PATH, DEFAULT_THEME_PATH } from './alias' @@ -20,10 +20,16 @@ export interface UserConfig { head?: HeadConfig[] themeConfig?: ThemeConfig locales?: Record - alias?: Record markdown?: MarkdownOptions + /** + * Opitons to pass on to @vitejs/plugin-vue + */ + vue?: VuePluginOptions + /** + * Vite config + */ + vite?: ViteConfig customData?: any - vueOptions?: VuePluginOptions exclude?: string[] } @@ -36,8 +42,9 @@ export interface SiteConfig { tempDir: string alias: AliasOptions pages: string[] - markdown?: MarkdownOptions - vueOptions?: VuePluginOptions + markdown: MarkdownOptions | undefined + vue: VuePluginOptions | undefined + vite: ViteConfig | undefined } const resolve = (root: string, file: string) => @@ -68,7 +75,8 @@ export async function resolveConfig( tempDir: path.resolve(APP_PATH, 'temp'), markdown: userConfig.markdown, alias: resolveAliases(themeDir, userConfig), - vueOptions: userConfig.vueOptions + vue: userConfig.vue, + vite: userConfig.vite } return config diff --git a/src/node/plugin.ts b/src/node/plugin.ts index 34f71405de1b..282b52a37851 100644 --- a/src/node/plugin.ts +++ b/src/node/plugin.ts @@ -1,5 +1,5 @@ import path from 'path' -import { Plugin, ResolvedConfig } from 'vite' +import { mergeConfig, Plugin, ResolvedConfig } from 'vite' import { SiteConfig, resolveSiteData } from './config' import { createMarkdownToVueRenderFn } from './markdownToVue' import { APP_PATH, SITE_DATA_REQUEST_PATH } from './alias' @@ -8,7 +8,8 @@ import { slash } from './utils/slash' import { OutputAsset, OutputChunk } from 'rollup' const hashRE = /\.(\w+)\.js$/ -const staticInjectMarkerRE = /\b(const _hoisted_\d+ = \/\*#__PURE__\*\/createStaticVNode)\("(.*)", (\d+)\)/g +const staticInjectMarkerRE = + /\b(const _hoisted_\d+ = \/\*#__PURE__\*\/createStaticVNode)\("(.*)", (\d+)\)/g const staticStripRE = /__VP_STATIC_START__.*?__VP_STATIC_END__/g const staticRestoreRE = /__VP_STATIC_(START|END)__/g @@ -24,7 +25,15 @@ const isPageChunk = ( export function createVitePressPlugin( root: string, - { configPath, alias, markdown, site, vueOptions, pages }: SiteConfig, + { + configPath, + alias, + markdown, + site, + vue: userVuePluginOptions, + vite: userViteConfig, + pages + }: SiteConfig, ssr = false, pageToHashMap?: Record ): Plugin[] { @@ -32,7 +41,7 @@ export function createVitePressPlugin( const vuePlugin = createVuePlugin({ include: [/\.vue$/, /\.md$/], - ...vueOptions + ...userVuePluginOptions }) let siteData = site @@ -47,7 +56,7 @@ export function createVitePressPlugin( }, config() { - return { + const baseConfig = { resolve: { alias }, @@ -60,6 +69,9 @@ export function createVitePressPlugin( exclude: ['@docsearch/js'] } } + return userViteConfig + ? mergeConfig(userViteConfig, baseConfig) + : baseConfig }, resolveId(id) {