Skip to content

Commit

Permalink
fix(plugin-compiler-web): 修复分包工程编译为 web 时可能会报错的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
lyfeyaj committed Jul 26, 2023
1 parent 1bb21f6 commit b9d5203
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions packages/plugin-compiler-web/src/plugins/generateJSXEntryPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,7 @@ export class GenerateJSXEntryPlugin implements Plugin {
// 处理分包里面的路径
if (subPackageJson.root && subPackageJson.pages) {
;(subPackageJson.pages || []).map((page: string) => {
pages.push(
addLeadingSlash(slash(path.join(subPackageJson.root, page)))
)
pages.push(addLeadingSlash(slash(page)))
})
}

Expand Down Expand Up @@ -384,13 +382,18 @@ export class GenerateJSXEntryPlugin implements Plugin {
// 生成各个页面对应的 jsx 文件
pages.map((page) => {
const pagePath = path.join(entriesRoot, `${page}.jsx`)
const pageContent = generatePageJSX(
entryHelpers.entries.get(page.slice(1)).entryName,
web.showBack,
web.showHeader
)
wrapper.fs.mem.mkdirpSync(path.dirname(pagePath))
wrapper.fs.mem.writeFileSync(pagePath, pageContent)
const entry = entryHelpers.entries.get(page.slice(1))
if (entry?.entryName) {
const pageContent = generatePageJSX(
entryHelpers.entries.get(page.slice(1)).entryName,
web.showBack,
web.showHeader
)
wrapper.fs.mem.mkdirpSync(path.dirname(pagePath))
wrapper.fs.mem.writeFileSync(pagePath, pageContent)
} else {
logger.warnOnce(`页面 ${page} 的 jsx 文件生成失败,原因:未找到文件`)
}
})

return { [MOR_GLOBAL_FILE(globalNameSuffix)]: mainEntryPath }
Expand Down

0 comments on commit b9d5203

Please sign in to comment.