Skip to content

Commit bc8f5a3

Browse files
committed
tweak style codegen for server-side rendering
1 parent cfcfc74 commit bc8f5a3

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

lib/loader.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,21 @@ module.exports = function (content) {
4747
var moduleId = 'data-v-' + genId(filePath)
4848
var styleRewriter = styleRewriterPath + '?id=' + moduleId
4949

50-
var needCssSourceMap =
51-
!isProduction &&
52-
this.sourceMap &&
53-
options.cssSourceMap !== false
50+
var cssLoaderOptions = ''
51+
if (!isProduction && this.sourceMap && options.cssSourceMap !== false) {
52+
cssLoaderOptions += '?sourceMap'
53+
}
54+
if (isProduction) {
55+
cssLoaderOptions += (cssLoaderOptions ? '&' : '?') + 'minimize'
56+
}
57+
58+
var bubleOptions = hasBuble && options.buble
59+
? '?' + JSON.stringify(options.buble)
60+
: ''
5461

55-
var bubleOptions = hasBuble && options.buble ? '?' + JSON.stringify(options.buble) : ''
5662
var defaultLoaders = {
5763
html: templateCompilerPath + '?id=' + moduleId,
58-
css: (isServer ? '' : styleLoaderPath + '!') + 'css-loader' + (needCssSourceMap ? '?sourceMap' : ''),
64+
css: styleLoaderPath + '!' + 'css-loader' + cssLoaderOptions,
5965
js: hasBuble ? ('buble-loader' + bubleOptions) : hasBabel ? 'babel-loader' : ''
6066
}
6167

@@ -205,14 +211,12 @@ module.exports = function (content) {
205211
output += '\n/* styles */\n'
206212
var hasModules = false
207213
parts.styles.forEach(function (style, i) {
208-
var moduleName = (style.module === true) ? '$style' : style.module
209-
210214
// require style
211-
if (isServer && !moduleName) return
212215
var requireString = style.src
213216
? getRequireForImport('styles', style, style.scoped)
214217
: getRequire('styles', style, i, style.scoped)
215218

219+
var moduleName = (style.module === true) ? '$style' : style.module
216220
// setCssModule
217221
if (moduleName) {
218222
if (!hasModules) {
@@ -225,10 +229,10 @@ module.exports = function (content) {
225229
} else {
226230
cssModules[moduleName] = true
227231

228-
// `style-loader` exposes the name-to-hash map directly
232+
// `(vue-)style-loader` exposes the name-to-hash map directly
229233
// `css-loader` exposes it in `.locals`
230-
// We drop `style-loader` in SSR, and add `.locals` here.
231-
if (isServer) {
234+
// add `.locals` if the user configured to not use style-loader.
235+
if (requireString.indexOf('style-loader') < 0) {
232236
requireString += '.locals'
233237
}
234238

0 commit comments

Comments
 (0)