Skip to content

Commit 76f650e

Browse files
authored
fix(config): enhance loadConfig to track user custom config presence (#5132)
1 parent ba777e1 commit 76f650e

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

packages-engine/config/src/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ export async function loadConfig<U extends UserConfig>(
1616
defaults: UserConfigDefaults = {},
1717
): Promise<LoadConfigResult<U>> {
1818
let inlineConfig = {} as U
19+
let hasUserCustomConfig = false
20+
1921
if (typeof configOrPath !== 'string') {
22+
hasUserCustomConfig = true
2023
inlineConfig = configOrPath
2124
if (inlineConfig.configFile === false) {
2225
return {
@@ -60,16 +63,16 @@ export async function loadConfig<U extends UserConfig>(
6063
...extraConfigSources,
6164
],
6265
cwd,
63-
defaults: inlineConfig,
6466
})
6567

6668
const result = await loader.load()
6769

68-
if (!isFile && !result.sources?.length) {
70+
if (!hasUserCustomConfig && !isFile && !result.config) {
6971
consola.error(`[@unocss/config] Config file not found in ${cyan(configOrPath)} - loading default config.`)
7072
}
7173

7274
result.config = Object.assign(defaults, inlineConfig, result.config ?? {})
75+
7376
if (result.config.configDeps) {
7477
result.sources = [
7578
...result.sources,

packages-integrations/vite/src/index.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,16 @@ export default function UnocssPlugin<Theme extends object>(
3232
configOrPath?: VitePluginConfig<Theme> | string,
3333
defaults: UserConfigDefaults = {},
3434
): Plugin[] {
35-
const ctx = createContext<VitePluginConfig>(configOrPath as any, {
36-
envMode: process.env.NODE_ENV === 'development'
37-
? 'dev'
38-
: 'build',
39-
...defaults,
40-
legacy: typeof configOrPath !== 'string'
41-
? (configOrPath?.legacy || { renderModernChunks: true })
42-
: { renderModernChunks: true },
43-
})
35+
const ctx = createContext<VitePluginConfig>(
36+
configOrPath as any,
37+
{
38+
envMode: process.env.NODE_ENV === 'development' ? 'dev' : 'build',
39+
...defaults,
40+
legacy: typeof configOrPath !== 'string'
41+
? (configOrPath?.legacy || { renderModernChunks: true })
42+
: { renderModernChunks: true },
43+
},
44+
)
4445
const inlineConfig = (configOrPath && typeof configOrPath !== 'string') ? configOrPath : {}
4546
const mode = inlineConfig.mode ?? 'global'
4647

0 commit comments

Comments
 (0)