Skip to content

Commit

Permalink
refactor: only run useCssModule code in non-global builds
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Feb 18, 2020
1 parent e8e6772 commit 86464e8
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions packages/runtime-core/src/helpers/useCssModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,29 @@ import { getCurrentInstance } from '../component'
import { EMPTY_OBJ } from '@vue/shared'
import { warn } from '../warning'

export function useCSSModule(name = '$style'): Record<string, string> {
const instance = getCurrentInstance()!
if (!instance) {
__DEV__ && warn(`useCSSModule must be called inside setup()`)
export const useCSSModule = (name = '$style'): Record<string, string> => {
if (!__GLOBAL__) {
const instance = getCurrentInstance()!
if (!instance) {
__DEV__ && warn(`useCSSModule must be called inside setup()`)
return EMPTY_OBJ
}
const modules = instance.type.__cssModules
if (!modules) {
__DEV__ && warn(`Current instance does not have CSS modules injected.`)
return EMPTY_OBJ
}
const mod = modules[name]
if (!mod) {
__DEV__ &&
warn(`Current instance does not have CSS module named "${name}".`)
return EMPTY_OBJ
}
return mod as Record<string, string>
} else {
if (__DEV__) {
warn(`useCSSModule() is not supported in the global build.`)
}
return EMPTY_OBJ
}
const modules = instance.type.__cssModules
if (!modules) {
__DEV__ && warn(`Current instance does not have CSS modules injected.`)
return EMPTY_OBJ
}
const mod = modules[name]
if (!mod) {
__DEV__ &&
warn(`Current instance does not have CSS module named "${name}".`)
return EMPTY_OBJ
}
return mod as Record<string, string>
}

0 comments on commit 86464e8

Please sign in to comment.