提交 49d53138 编写于 作者: D DCloud_LXH

fix(mp): mp app.json usingComponents use absolute path question/138662

上级 4237a704
......@@ -64,15 +64,18 @@ export function findChangedJsonFiles() {
extend(newJson.usingComponents, jsonUsingComponentsCache.get(filename))
const usingComponents = newJson.usingComponents as Record<string, string>
// 格式化为相对路径,这样作为分包也可以直接运行
Object.keys(usingComponents).forEach((name) => {
const componentFilename = usingComponents[name]
if (componentFilename.startsWith('/')) {
usingComponents[name] = relativeFile(
filename,
componentFilename.slice(1)
)
}
})
// app.json mp-baidu 在 win 不支持相对路径。所有平台改用绝对路径
if (filename !== 'app') {
Object.keys(usingComponents).forEach((name) => {
const componentFilename = usingComponents[name]
if (componentFilename.startsWith('/')) {
usingComponents[name] = relativeFile(
filename,
componentFilename.slice(1)
)
}
})
}
const jsonStr = JSON.stringify(newJson, null, 2)
if (jsonFilesCache.get(filename) !== jsonStr) {
......
......@@ -40,24 +40,6 @@ export function mergeMiniProgramAppJson(
})
}
function normalizeUsingComponentsPath(
usingComponents: PageWindowOptions['usingComponents'],
platform: UniApp.PLATFORM
) {
if (platform === 'mp-baidu') {
const flag = './'
const _usingComponents: PageWindowOptions['usingComponents'] = {}
for (const key in usingComponents) {
const componentPath = usingComponents[key]
_usingComponents[key] = componentPath.startsWith(flag)
? componentPath.replace(flag, '/')
: componentPath
}
return _usingComponents
}
return usingComponents
}
function parsePagesJson(
jsonStr: string,
platform: UniApp.PLATFORM,
......@@ -153,10 +135,7 @@ function parsePagesJson(
const { usingComponents } = windowOptions as PageWindowOptions
if (usingComponents) {
delete (windowOptions as PageWindowOptions).usingComponents
appJson.usingComponents = normalizeUsingComponentsPath(
usingComponents,
platform
)
appJson.usingComponents = usingComponents
} else {
delete appJson.usingComponents
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册