From 1ff2c817a18bd45a44e133186f74a51b57b213e8 Mon Sep 17 00:00:00 2001 From: anchengjian Date: Thu, 22 Mar 2018 21:24:52 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix=20#153:=20=E6=A0=B9=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=20style=20=E6=A8=A1=E5=9D=97=EF=BC=8C?= =?UTF-8?q?=E4=B8=8D=E7=94=9F=E6=88=90=E9=A1=B5=E9=9D=A2=E7=9A=84=20wxss?= =?UTF-8?q?=EF=BC=8C=E8=A1=A5=E9=BD=90=E5=86=85=E5=AE=B9=E6=96=B9=E4=BE=BF?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=20vendor.wxss?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/loader.js | 7 +++++++ lib/mp-compiler/util.js | 16 ++++++++++++++++ lib/selector.js | 2 ++ 3 files changed, 25 insertions(+) diff --git a/lib/loader.js b/lib/loader.js index 4cb2135..c4d00c3 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -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)?(?:\?[^!]+)?)(?:!|$)/ @@ -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 diff --git a/lib/mp-compiler/util.js b/lib/mp-compiler/util.js index b4caea6..80b064a 100644 --- a/lib/mp-compiler/util.js +++ b/lib/mp-compiler/util.js @@ -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, diff --git a/lib/selector.js b/lib/selector.js index 7a72775..facb9e0 100644 --- a/lib/selector.js +++ b/lib/selector.js @@ -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() @@ -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) } From 49f5e3a14ed389efca3420d5d35d35d2e1559182 Mon Sep 17 00:00:00 2001 From: anchengjian Date: Fri, 23 Mar 2018 19:31:16 +0800 Subject: [PATCH 2/2] new version 1.0.9 --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index e84b5ac..68741d9 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -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", @@ -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",