Skip to content

Commit

Permalink
fix(cli): 修复h5分包功能出现没有Root的pages的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Littly committed Oct 24, 2018
1 parent 22831b3 commit d6f0971
Showing 1 changed file with 13 additions and 30 deletions.
43 changes: 13 additions & 30 deletions packages/taro-cli/src/h5.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ const FILE_TYPE = {
NORMAL: 'NORMAL'
}

const isUnderSubPackages = (parentPath) => (parentPath.isObjectProperty() && /subPackages/i.test(parentPath.node.key.name))

function processEntry (code, filePath) {
let ast = wxTransformer({
code,
Expand Down Expand Up @@ -265,37 +267,18 @@ function processEntry (code, filePath) {
const value = node.value
const keyName = t.isIdentifier(key) ? key.name : key.value
if (keyName === 'pages' && t.isArrayExpression(value)) {
value.elements.forEach(v => {
pages.push(v.value)
})
} else if (keyName === 'subPackages' && t.isArrayExpression(value)) {
// 处理分包逻辑
value.elements.forEach(v => {
if (!t.isObjectExpression(v)) return
let root = null
let subPages = []
v.properties.forEach(va => {
if (!t.isObjectProperty(va) || !t.isIdentifier(va.key)) return
const subPackageKey = va.key.name
const subPackageValue = va.value
if (subPackageKey === 'root') {
root = subPackageValue.value
return
}
if (subPackageKey === 'pages' && t.isArrayExpression(subPackageValue)) {
subPackageValue.elements.forEach(val => {
subPages.push(val.value)
})
}
})
if (root === null) return
subPages.forEach(va => {
let pagePath = `${root}/${va}`
pagePath = pagePath.replace(/\/{2,}/g, '/')
if (pages.indexOf(pagePath) < 0) {
pages.push(pagePath)
}
const subPackageParent = astPath.findParent(isUnderSubPackages)
let root = ''
if (subPackageParent) {
/* 在subPackages属性下,说明是分包页面,需要处理root属性 */
const rootNode = astPath.parent.properties.find(v => {
return t.isIdentifier(v.key, { name: 'root' })
})
root = rootNode ? rootNode.value.value : ''
}
value.elements.forEach(v => {
const pagePath = `${root}${v.value}`.replace(/\/{2,}/g, '/')
pages.push(pagePath)
})
} else if (keyName === 'tabBar' && t.isObjectExpression(value)) {
// tabBar
Expand Down

0 comments on commit d6f0971

Please sign in to comment.