Skip to content

Commit 1ff2c81

Browse files
committed
fix #153: 根组件没有 style 模块,不生成页面的 wxss,补齐内容方便加载 vendor.wxss
1 parent eacda9d commit 1ff2c81

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

lib/loader.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var hasBuble = !!tryRequire('buble-loader')
2424

2525
// for mp js
2626
var { compileMP, compileMPScript } = require('./mp-compiler')
27+
var { defaultStylePart } = require('./mp-compiler/util')
2728

2829
var rewriterInjectRE = /\b(css(?:-loader)?(?:\?[^!]+)?)(?:!|$)/
2930

@@ -99,6 +100,12 @@ module.exports = function (content) {
99100

100101
var output = ''
101102
var parts = parse(content, fileName, this.sourceMap)
103+
104+
// fix #153: 根组件没有 style 模块,不生成页面的 wxss,补齐内容方便加载 vendor.wxss
105+
if (!parts.styles.length) {
106+
parts.styles.push(defaultStylePart)
107+
}
108+
102109
var hasScoped = parts.styles.some(function (s) { return s.scoped })
103110
var hasComment = parts.template && parts.template.attrs && parts.template.attrs.comments
104111

lib/mp-compiler/util.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,23 @@ function getPathPrefix (src) {
114114
return `${'../'.repeat(length)}`
115115
}
116116

117+
const defaultStylePart = {
118+
type: 'style',
119+
content: '\n',
120+
start: 0,
121+
attrs: {},
122+
end: 1,
123+
map: {
124+
version: 3,
125+
sources: [],
126+
names: [],
127+
mappings: '',
128+
sourcesContent: []
129+
}
130+
}
131+
117132
module.exports = {
133+
defaultStylePart,
118134
cacheFileInfo,
119135
getFileInfo,
120136
getCompNameBySrc,

lib/selector.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
var path = require('path')
66
var parse = require('./parser')
77
var loaderUtils = require('loader-utils')
8+
var { defaultStylePart } = require('./mp-compiler/util')
89

910
module.exports = function (content) {
1011
this.cacheable()
@@ -16,5 +17,6 @@ module.exports = function (content) {
1617
if (Array.isArray(part)) {
1718
part = part[query.index]
1819
}
20+
part = part || defaultStylePart
1921
this.callback(null, part.content, part.map)
2022
}

0 commit comments

Comments
 (0)