Skip to content

Commit 86464e8

Browse files
committed
refactor: only run useCssModule code in non-global builds
1 parent e8e6772 commit 86464e8

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

packages/runtime-core/src/helpers/useCssModule.ts

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,29 @@ import { getCurrentInstance } from '../component'
22
import { EMPTY_OBJ } from '@vue/shared'
33
import { warn } from '../warning'
44

5-
export function useCSSModule(name = '$style'): Record<string, string> {
6-
const instance = getCurrentInstance()!
7-
if (!instance) {
8-
__DEV__ && warn(`useCSSModule must be called inside setup()`)
5+
export const useCSSModule = (name = '$style'): Record<string, string> => {
6+
if (!__GLOBAL__) {
7+
const instance = getCurrentInstance()!
8+
if (!instance) {
9+
__DEV__ && warn(`useCSSModule must be called inside setup()`)
10+
return EMPTY_OBJ
11+
}
12+
const modules = instance.type.__cssModules
13+
if (!modules) {
14+
__DEV__ && warn(`Current instance does not have CSS modules injected.`)
15+
return EMPTY_OBJ
16+
}
17+
const mod = modules[name]
18+
if (!mod) {
19+
__DEV__ &&
20+
warn(`Current instance does not have CSS module named "${name}".`)
21+
return EMPTY_OBJ
22+
}
23+
return mod as Record<string, string>
24+
} else {
25+
if (__DEV__) {
26+
warn(`useCSSModule() is not supported in the global build.`)
27+
}
928
return EMPTY_OBJ
1029
}
11-
const modules = instance.type.__cssModules
12-
if (!modules) {
13-
__DEV__ && warn(`Current instance does not have CSS modules injected.`)
14-
return EMPTY_OBJ
15-
}
16-
const mod = modules[name]
17-
if (!mod) {
18-
__DEV__ &&
19-
warn(`Current instance does not have CSS module named "${name}".`)
20-
return EMPTY_OBJ
21-
}
22-
return mod as Record<string, string>
2330
}

0 commit comments

Comments
 (0)