Skip to content

Commit

Permalink
Merge pull request #43 from mpvue/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
anchengjian authored Aug 19, 2018
2 parents 59045bc + e8e7080 commit 965405f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 19 deletions.
8 changes: 6 additions & 2 deletions lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var hasBuble = !!tryRequire('buble-loader')

// for mp js
var { compileMP, compileMPScript } = require('./mp-compiler')
var { defaultStylePart } = require('./mp-compiler/util')
var { defaultPart } = require('./mp-compiler/util')

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

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

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

var hasScoped = parts.styles.some(function (s) { return s.scoped })
Expand Down
2 changes: 1 addition & 1 deletion lib/mp-compiler/parse-ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function delint (sourceFile) {
switch (node.kind) {
case ts.SyntaxKind.ImportDeclaration:
// 只处理 import Comp from 'xxx.vue'
if (node.importClause.name) {
if (node.importClause && node.importClause.name) {
importsMap[node.importClause.name.escapedText] = node.moduleSpecifier.text
}
// report(node, 'import')
Expand Down
27 changes: 14 additions & 13 deletions lib/mp-compiler/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,23 +121,24 @@ function getBabelrc (src) {
return ''
}

const defaultStylePart = {
type: 'style',
content: '\n',
start: 0,
attrs: {},
end: 1,
map: {
version: 3,
sources: [],
names: [],
mappings: '',
sourcesContent: []
const defaultPart = type => {
return {
type,
content: '\n',
start: 0,
attrs: {},
end: 1,
map: {
version: 3,
sources: [],
names: [],
mappings: '',
sourcesContent: []
}
}

module.exports = {
defaultStylePart,
defaultPart,
cacheFileInfo,
getFileInfo,
getCompNameAndSrc,
Expand Down
4 changes: 2 additions & 2 deletions lib/selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
var path = require('path')
var parse = require('./parser')
var loaderUtils = require('loader-utils')
var { defaultStylePart } = require('./mp-compiler/util')
var { defaultPart } = require('./mp-compiler/util')

module.exports = function (content) {
this.cacheable()
Expand All @@ -17,6 +17,6 @@ module.exports = function (content) {
if (Array.isArray(part)) {
part = part[query.index]
}
part = part || defaultStylePart
part = part || defaultPart('style')
this.callback(null, part.content, part.map)
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mpvue-loader",
"version": "1.1.2",
"version": "1.1.3",
"description": "mpvue single-file component loader for Webpack",
"main": "index.js",
"repository": {
Expand Down

0 comments on commit 965405f

Please sign in to comment.