Skip to content

Commit 6f18500

Browse files
authored
Merge pull request #11 from mpvue/develop
Develop
2 parents 3d977b9 + 2905ef5 commit 6f18500

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

lib/mp-compiler/index.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ const {
2222
getPageSrc
2323
} = require('./util')
2424

25-
function createSlotsWxml (emitFile, slots) {
26-
cacheSlots(slots)
27-
const allSlots = getSlots()
28-
const content = Object.keys(allSlots).map(v => allSlots[v].code).join('\n')
25+
function createSlotsWxml (emitFile, slots, importCode) {
26+
cacheSlots(slots, importCode)
27+
const content = getSlots()
2928
if (content.trim()) {
3029
emitFile('components/slots.wxml', htmlBeautify(content))
3130
}
@@ -34,11 +33,11 @@ function createSlotsWxml (emitFile, slots) {
3433
// 调用 compiler 生成 wxml
3534
function genComponentWxml (compiled, options, emitFile, emitError, emitWarning) {
3635
options.components['slots'] = { src: 'slots', name: 'slots' }
37-
const { code: wxmlCodeStr, compiled: cp, slots } = compiler.compileToWxml(compiled, options)
36+
const { code: wxmlCodeStr, compiled: cp, slots, importCode } = compiler.compileToWxml(compiled, options)
3837
const { mpErrors, mpTips } = cp
3938

4039
// 缓存 slots,延迟编译
41-
createSlotsWxml(emitFile, slots)
40+
createSlotsWxml(emitFile, slots, importCode)
4241

4342
if (mpErrors && mpErrors.length) {
4443
emitError(

lib/mp-compiler/util.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,18 @@ function covertCCVar (str) {
7070

7171
// 缓存所有的 slots 节点,生成一个文件
7272
const slotsCache = Object.create(null)
73-
function cacheSlots (slots) {
73+
const importCodeCache = Object.create(null)
74+
75+
function cacheSlots (slots, importCode) {
7476
Object.keys(slots).forEach(k => {
7577
slotsCache[k] = slots[k]
7678
})
79+
importCodeCache[importCode] = importCode
7780
}
78-
function getSlots (slotName) {
79-
return slotName ? slotsCache[slotName] : slotsCache
81+
function getSlots () {
82+
const allImportCode = Object.keys(importCodeCache).map(v => importCodeCache[v]).join('\n').replace('<import src="slots" />', '')
83+
const allSlots = Object.keys(slotsCache).map(v => slotsCache[v].code).join('\n')
84+
return allImportCode + allSlots
8085
}
8186

8287
// 包大小优化: build 模式不需要美化 wxml

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mpvue-loader",
3-
"version": "1.0.10",
3+
"version": "1.0.11",
44
"description": "mpvue single-file component loader for Webpack",
55
"main": "index.js",
66
"repository": {

0 commit comments

Comments
 (0)