From: Evan You Date: Tue, 18 Feb 2020 18:23:30 +0000 (-0500) Subject: refactor: only run useCssModule code in non-global builds X-Git-Tag: v3.0.0-alpha.5~8 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=86464e8c049a83aa0642ce2f5f02a35327fa9cac;p=thirdparty%2Fvuejs%2Fcore.git refactor: only run useCssModule code in non-global builds --- diff --git a/packages/runtime-core/src/helpers/useCssModule.ts b/packages/runtime-core/src/helpers/useCssModule.ts index b838835f04..838ac604d8 100644 --- a/packages/runtime-core/src/helpers/useCssModule.ts +++ b/packages/runtime-core/src/helpers/useCssModule.ts @@ -2,22 +2,29 @@ import { getCurrentInstance } from '../component' import { EMPTY_OBJ } from '@vue/shared' import { warn } from '../warning' -export function useCSSModule(name = '$style'): Record { - const instance = getCurrentInstance()! - if (!instance) { - __DEV__ && warn(`useCSSModule must be called inside setup()`) +export const useCSSModule = (name = '$style'): Record => { + 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 + } 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 }