Skip to content

Commit 74fa31e

Browse files
authored
Merge pull request #37 from mpvue/fix-empty-script
fix: #562 添加默认 script 标签
2 parents d7f7806 + b0eea21 commit 74fa31e

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

lib/loader.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +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')
27+
var { defaultPart } = require('./mp-compiler/util')
2828

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

@@ -103,7 +103,11 @@ module.exports = function (content) {
103103

104104
// fix #153: 根组件没有 style 模块,不生成页面的 wxss,补齐内容方便加载 vendor.wxss
105105
if (!parts.styles.length) {
106-
parts.styles.push(defaultStylePart)
106+
parts.styles.push(defaultPart('style'))
107+
}
108+
// fix #562: 组件没有 script 模块,会阻塞编译
109+
if (!parts.script) {
110+
parts.script = defaultPart('script')
107111
}
108112

109113
var hasScoped = parts.styles.some(function (s) { return s.scoped })

lib/mp-compiler/util.js

+14-13
Original file line numberDiff line numberDiff line change
@@ -121,23 +121,24 @@ function getBabelrc (src) {
121121
return ''
122122
}
123123

124-
const defaultStylePart = {
125-
type: 'style',
126-
content: '\n',
127-
start: 0,
128-
attrs: {},
129-
end: 1,
130-
map: {
131-
version: 3,
132-
sources: [],
133-
names: [],
134-
mappings: '',
135-
sourcesContent: []
124+
const defaultPart = type => {
125+
return {
126+
type,
127+
content: '\n',
128+
start: 0,
129+
attrs: {},
130+
end: 1,
131+
map: {
132+
version: 3,
133+
sources: [],
134+
names: [],
135+
mappings: '',
136+
sourcesContent: []
136137
}
137138
}
138139

139140
module.exports = {
140-
defaultStylePart,
141+
defaultPart,
141142
cacheFileInfo,
142143
getFileInfo,
143144
getCompNameAndSrc,

lib/selector.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +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')
8+
var { defaultPart } = require('./mp-compiler/util')
99

1010
module.exports = function (content) {
1111
this.cacheable()
@@ -17,6 +17,6 @@ module.exports = function (content) {
1717
if (Array.isArray(part)) {
1818
part = part[query.index]
1919
}
20-
part = part || defaultStylePart
20+
part = part || defaultPart('style')
2121
this.callback(null, part.content, part.map)
2222
}

0 commit comments

Comments
 (0)