问题描述:
支付宝小程序在使用map组件时,使用高级渲染需要使用xml组件,在manifest.json下配置include字段,编译完没有该字段,不生效。
这里是支付宝文档:
• 布局的 XML 文件默认会被 IDE 打包工具忽略,需要在根目录 mini.project.json 配置规则里将 xml 打到小程序中。
{
"include":["*/.xml"] // 配置包含 xml
}
原因: 社区文公开发人员后,可能是由于hbuilderX内配置文件未添加该项所致
两种解决方案
1临时解决方案:
- 应用程序,右键,显示包内容,content
- HBuilderX/plugins/uniapp-cli/node_modules/@dcloudio/webpack-uni-pages-loader/lib/platforms/mp-alipay.js
- 替换mp-alipay.js 内容为下边代码,官方给的,嘿嘿
const fs = require('fs')
const path = require('path')
const {
parsePages,
getPlatformProject
} = require('@dcloudio/uni-cli-shared')
const {
updateAppJsonUsingComponents
} = require('@dcloudio/uni-cli-shared/lib/cache')
const {
hasOwn,
parseStyle,
parseTabBar,
NON_APP_JSON_KEYS
} = require('../util')
function defaultCopy (name, value, json) {
json[name] = value
}
const pagesJson2AppJson = {
globalStyle: function (name, value, json) {
json.window = parseStyle(value)
if (json.window.usingComponents) {
json.usingComponents = json.window.usingComponents
delete json.window.usingComponents
}
},
tabBar: function (name, value, json) {
json.tabBar = parseTabBar(value)
},
preloadRule: defaultCopy
}
function copyToJson (json, fromJson, options) {
Object.keys(options).forEach(name => {
if (hasOwn(fromJson, name)) {
options[name](name, fromJson[name], json)
}
})
}
const projectKeys = ['component2', 'enableAppxNg', 'include']
module.exports = function (pagesJson, manifestJson) {
const app = {
pages: [],
subPackages: []
}
const subPackages = {}
parsePages(pagesJson, function (page) {
app.pages.push(page.path)
}, function (root, page, subPackage) {
if (!subPackages[root]) {
subPackages[root] = {
root,
pages: []
}
Object.keys(subPackage).forEach(name => {
if (['root', 'pages'].indexOf(name) === -1) {
subPackages[root][name] = subPackage[name]
}
})
}
subPackages[root].pages.push(page.path)
})
Object.keys(subPackages).forEach(root => {
app.subPackages.push(subPackages[root])
})
copyToJson(app, pagesJson, pagesJson2AppJson)
const platformJson = manifestJson['mp-alipay'] || {}
Object.keys(platformJson).forEach(key => {
if (!projectKeys.includes(key) && !NON_APP_JSON_KEYS.includes(key)) {
// usingComponents 是编译模式开关,需要过滤,不能拷贝到 app
app[key] = platformJson[key]
}
})
if (app.usingComponents) {
updateAppJsonUsingComponents(app.usingComponents)
}
const projectName = getPlatformProject()
let project = {}
const projectPath = path.resolve(process.env.UNI_INPUT_DIR, projectName)
if (fs.existsSync(projectPath)) {
project = require(projectPath)
} else {
if (platformJson.appid) {
project.appid = platformJson.appid
}
project.component2 = hasOwn(platformJson, 'component2') ? platformJson.component2 : true
project.enableAppxNg = hasOwn(platformJson, 'enableAppxNg') ? platformJson.enableAppxNg : true
if (hasOwn(platformJson, 'include')) {
project.include = platformJson.include
}
}
return [{
name: 'app',
content: app
}, {
name: 'mini.project',
content: project
}]
}