-
Notifications
You must be signed in to change notification settings - Fork 907
/
cssModules.ts
28 lines (24 loc) 路 688 Bytes
/
cssModules.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
export function genCSSModulesCode(
id: string,
index: number,
request: string,
moduleName: string | boolean,
needsHotReload: boolean
): string {
const styleVar = `style${index}`
let code = `\nimport * as ${styleVar} from ${request}`
// inject variable
const name = typeof moduleName === 'string' ? moduleName : '$style'
// omit no default export error
code += `\ncssModules["${name}"] = {...${styleVar}}.default || ${styleVar}`
if (needsHotReload) {
code += `
if (module.hot) {
module.hot.accept(${request}, () => {
cssModules["${name}"] = {...${styleVar}}.default || ${styleVar}
__VUE_HMR_RUNTIME__.rerender("${id}")
})
}`
}
return code
}