Skip to content

Commit 6a6da42

Browse files
authored
Merge pull request mpvue#43 from mpvue/develop
Develop
2 parents d093c11 + e62bd41 commit 6a6da42

File tree

5 files changed

+24
-19
lines changed

5 files changed

+24
-19
lines changed

Diff for: 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 })

Diff for: lib/mp-compiler/parse-ts.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function delint (sourceFile) {
5757
switch (node.kind) {
5858
case ts.SyntaxKind.ImportDeclaration:
5959
// 只处理 import Comp from 'xxx.vue'
60-
if (node.importClause.name) {
60+
if (node.importClause && node.importClause.name) {
6161
importsMap[node.importClause.name.escapedText] = node.moduleSpecifier.text
6262
}
6363
// report(node, 'import')

Diff for: 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,

Diff for: 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
}

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mpvue-loader",
3-
"version": "1.1.2",
3+
"version": "1.1.3",
44
"description": "mpvue single-file component loader for Webpack",
55
"main": "index.js",
66
"repository": {

0 commit comments

Comments
 (0)