@@ -13,6 +13,7 @@ import {
1313} from '@vue/compiler-sfc'
1414import { selectBlock } from './select'
1515import { genHotReloadCode } from './hotReload'
16+ import { genCSSModulesCode } from './cssModules'
1617
1718const VueLoaderPlugin = require ( './plugin' )
1819
@@ -97,7 +98,7 @@ const loader: webpack.loader.Loader = function(source) {
9798 const needsHotReload =
9899 ! isServer &&
99100 ! isProduction &&
100- ( descriptor . script || descriptor . template ) &&
101+ ! ! ( descriptor . script || descriptor . template ) &&
101102 options . hotReload !== false
102103
103104 // template
@@ -121,12 +122,12 @@ const loader: webpack.loader.Loader = function(source) {
121122 const query = `?vue&type=script${ attrsQuery } ${ inheritQuery } `
122123 const scriptRequest = stringifyRequest ( src + query )
123124 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
126126 }
127127
128128 // styles
129129 let stylesCode = ``
130+ let hasCSSModules = false
130131 if ( descriptor . styles . length ) {
131132 descriptor . styles . forEach ( ( style : SFCStyleBlock , i : number ) => {
132133 const src = style . src || resourcePath
@@ -137,8 +138,22 @@ const loader: webpack.loader.Loader = function(source) {
137138 const idQuery = style . scoped ? `&id=${ id } ` : ``
138139 const query = `?vue&type=style&index=${ i } ${ idQuery } ${ attrsQuery } ${ inheritQuery } `
139140 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
142157 } )
143158 }
144159
0 commit comments