Skip to content

Commit 584189c

Browse files
committed
do not insert style for server bundle + trim css
1 parent a218d67 commit 584189c

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

lib/loader.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ var defaultLang = {
3232

3333
module.exports = function (content) {
3434
this.cacheable()
35+
var isServer = this.options.target === 'node'
3536
var loaderContext = this
3637
var options = this.options.vue || {}
3738
var query = loaderUtils.parseQuery(this.query)
@@ -133,17 +134,17 @@ module.exports = function (content) {
133134
}
134135

135136
var parts = parse(content, fileName, this.sourceMap)
136-
var hasScoped = false
137+
var hasScoped = parts.styles.some(function (s) { return s.scoped })
137138
var output = 'var __vue_script__\n'
138139

139140
// add requires for styles
140-
parts.styles.forEach(function (style, i) {
141-
var scoped = style.scoped
142-
if (scoped) hasScoped = true
143-
output += style.src
144-
? getRequireForImport('styles', style, scoped)
145-
: getRequire('styles', style, i, scoped)
146-
})
141+
if (!isServer) {
142+
parts.styles.forEach(function (style, i) {
143+
output += style.src
144+
? getRequireForImport('styles', style, style.scoped)
145+
: getRequire('styles', style, i, style.scoped)
146+
})
147+
}
147148

148149
// add require for script
149150
var script = parts.script

lib/style-rewriter.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ var addId = postcss.plugin('add-id', function (opts) {
2727
}
2828
})
2929

30+
var trim = postcss.plugin('trim', function (opts) {
31+
return function (css) {
32+
css.walk(function (node) {
33+
if (node.type === 'rule' || node.type == 'atrule') {
34+
node.raws.before = node.raws.after = '\n'
35+
}
36+
})
37+
}
38+
})
39+
3040
module.exports = function (css, map) {
3141
this.cacheable()
3242
var cb = this.async()
@@ -44,7 +54,7 @@ module.exports = function (css, map) {
4454
} else if (isObject(postcssOptions) && postcssOptions.plugins) {
4555
plugins = postcssOptions.plugins
4656
}
47-
plugins = plugins ? plugins.slice() : [] // make sure to copy it
57+
plugins = [trim].concat(plugins || [])
4858

4959
// scoped css
5060
if (query.scoped) {

0 commit comments

Comments
 (0)