mirror of https://github.com/YunYouJun/valaxy
fix: load userRoot valaxy.config.ts when load addon not exist valaxy.config.ts, close #206
This commit is contained in:
parent
8aeb515e98
commit
7275b963ff
|
@ -30,7 +30,7 @@ More info see [valaxy.site](https://valaxy.site).
|
|||
* User Config
|
||||
* do not use export const, because c12 will set as child property
|
||||
*/
|
||||
const config: UserConfig<UserThemeConfig> = {
|
||||
export default defineValaxyConfig<ThemeConfig>({
|
||||
theme: 'yun',
|
||||
|
||||
themeConfig: {
|
||||
|
@ -39,7 +39,5 @@ const config: UserConfig<UserThemeConfig> = {
|
|||
title: '云游君的小站',
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default config
|
||||
})
|
||||
```
|
||||
|
|
|
@ -59,11 +59,7 @@ I will compare Valaxy with the existing Hexo (popular static blog framework) and
|
|||
import type { UserConfig } from 'valaxy'
|
||||
import type { UserThemeConfig } from 'valaxy-theme-yun'
|
||||
|
||||
/**
|
||||
* User Config
|
||||
* do not use export const, because c12 will set as child property
|
||||
*/
|
||||
const config: UserConfig<UserThemeConfig> = {
|
||||
export default defineValaxyConfig<ThemeConfig>({
|
||||
theme: 'yun',
|
||||
|
||||
themeConfig: {
|
||||
|
@ -72,9 +68,7 @@ const config: UserConfig<UserThemeConfig> = {
|
|||
title: '云游君的小站',
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default config
|
||||
})
|
||||
```
|
||||
|
||||
::: zh-CN
|
||||
|
|
|
@ -11,7 +11,7 @@ export async function loadConfigFromFile<T>(
|
|||
file: string,
|
||||
options: LoadConfigFromFileOptions = {},
|
||||
) {
|
||||
const { config: userValaxyConfig, sources } = await await loadConfig<T>({
|
||||
const { config: userValaxyConfig, sources } = await loadConfig<T>({
|
||||
sources: { files: file, rewrite: options.rewrite },
|
||||
cwd: options.cwd || process.cwd(),
|
||||
})
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import { existsSync } from 'node:fs'
|
||||
import { resolve } from 'node:path'
|
||||
import { mergeConfig as mergeViteConfig } from 'vite'
|
||||
import { createDefu } from 'defu'
|
||||
import { isFunction } from '@antfu/utils'
|
||||
|
@ -66,14 +68,21 @@ export async function resolveValaxyConfig(options: ValaxyEntryOptions) {
|
|||
export async function resolveAddonConfig(addons: ValaxyAddonResolver[], options?: ResolvedValaxyOptions) {
|
||||
let valaxyConfig: ValaxyNodeConfig = {} as ValaxyNodeConfig
|
||||
for (const addon of addons) {
|
||||
const { config, configFile } = await loadConfigFromFile<ValaxyNodeConfig>('valaxy.config', {
|
||||
// unconfig get node_modules/valaxy-addon-xxx/valaxy.config.ts(not exist) but get userRoot/valaxy.config.ts
|
||||
// so we need to check if valaxy.config.ts exist
|
||||
if (!existsSync(resolve(addon.root, 'valaxy.config.ts')))
|
||||
continue
|
||||
|
||||
const { config, configFile } = await loadConfigFromFile('valaxy.config', {
|
||||
rewrite<F = ValaxyNodeConfig | ValaxyAddonFn>(obj: F, _filepath: string) {
|
||||
return (typeof obj === 'function' ? obj(addon, options!) : obj)
|
||||
},
|
||||
cwd: addon.root,
|
||||
})
|
||||
|
||||
if (!config)
|
||||
continue
|
||||
|
||||
addon.configFile = configFile
|
||||
valaxyConfig = mergeValaxyConfig(config, valaxyConfig)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue