Skip to content

Commit

Permalink
Merge pull request #7 from mpvue/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
anchengjian authored Mar 23, 2018
2 parents 11afc53 + 49f5e3a commit 4d08ffe
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
7 changes: 7 additions & 0 deletions lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var hasBuble = !!tryRequire('buble-loader')

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

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

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

var output = ''
var parts = parse(content, fileName, this.sourceMap)

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

var hasScoped = parts.styles.some(function (s) { return s.scoped })
var hasComment = parts.template && parts.template.attrs && parts.template.attrs.comments

Expand Down
16 changes: 16 additions & 0 deletions lib/mp-compiler/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,23 @@ function getPathPrefix (src) {
return `${'../'.repeat(length)}`
}

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

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

module.exports = function (content) {
this.cacheable()
Expand All @@ -16,5 +17,6 @@ module.exports = function (content) {
if (Array.isArray(part)) {
part = part[query.index]
}
part = part || defaultStylePart
this.callback(null, part.content, part.map)
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mpvue-loader",
"version": "1.0.8",
"version": "1.0.9",
"description": "mpvue single-file component loader for Webpack",
"main": "index.js",
"repository": {
Expand Down Expand Up @@ -67,7 +67,7 @@
},
"peerDependencies": {
"css-loader": "*",
"mpvue-template-compiler": "^1.0.6"
"mpvue-template-compiler": "^1.0.7"
},
"devDependencies": {
"babel-core": "^6.25.0",
Expand All @@ -90,7 +90,7 @@
"marked": "^0.3.6",
"memory-fs": "^0.4.1",
"mkdirp": "^0.5.1",
"mpvue-template-compiler": "^1.0.6",
"mpvue-template-compiler": "^1.0.7",
"mocha": "^3.4.2",
"node-libs-browser": "^2.0.0",
"normalize-newline": "^3.0.0",
Expand Down

0 comments on commit 4d08ffe

Please sign in to comment.