@@ -13,6 +13,7 @@ import {
13
13
} from '@vue/compiler-sfc'
14
14
import { selectBlock } from './select'
15
15
import { genHotReloadCode } from './hotReload'
16
+ import { genCSSModulesCode } from './cssModules'
16
17
17
18
const VueLoaderPlugin = require ( './plugin' )
18
19
@@ -97,7 +98,7 @@ const loader: webpack.loader.Loader = function(source) {
97
98
const needsHotReload =
98
99
! isServer &&
99
100
! isProduction &&
100
- ( descriptor . script || descriptor . template ) &&
101
+ ! ! ( descriptor . script || descriptor . template ) &&
101
102
options . hotReload !== false
102
103
103
104
// template
@@ -121,12 +122,12 @@ const loader: webpack.loader.Loader = function(source) {
121
122
const query = `?vue&type=script${ attrsQuery } ${ inheritQuery } `
122
123
const scriptRequest = stringifyRequest ( src + query )
123
124
scriptImport =
124
- `import script from ${ scriptRequest } \n` +
125
- `export * from ${ scriptRequest } ` // support named exports
125
+ `import script from ${ scriptRequest } \n` + `export * from ${ scriptRequest } ` // support named exports
126
126
}
127
127
128
128
// styles
129
129
let stylesCode = ``
130
+ let hasCSSModules = false
130
131
if ( descriptor . styles . length ) {
131
132
descriptor . styles . forEach ( ( style : SFCStyleBlock , i : number ) => {
132
133
const src = style . src || resourcePath
@@ -137,8 +138,22 @@ const loader: webpack.loader.Loader = function(source) {
137
138
const idQuery = style . scoped ? `&id=${ id } ` : ``
138
139
const query = `?vue&type=style&index=${ i } ${ idQuery } ${ attrsQuery } ${ inheritQuery } `
139
140
const styleRequest = stringifyRequest ( src + query )
140
- // TODO CSS Modules & SSR
141
- stylesCode += `import ${ styleRequest } `
141
+ if ( style . module ) {
142
+ if ( ! hasCSSModules ) {
143
+ stylesCode += `const cssModules = script.__cssModules = {}`
144
+ hasCSSModules = true
145
+ }
146
+ stylesCode += genCSSModulesCode (
147
+ id ,
148
+ i ,
149
+ styleRequest ,
150
+ style . module ,
151
+ needsHotReload
152
+ )
153
+ } else {
154
+ stylesCode += `\nimport ${ styleRequest } `
155
+ }
156
+ // TODO SSR critical CSS collection
142
157
} )
143
158
}
144
159
0 commit comments