Skip to content

Commit

Permalink
feat:添加局部构建兜底页面
Browse files Browse the repository at this point in the history
  • Loading branch information
Blackgan3 committed Aug 9, 2023
1 parent 2a06796 commit 664dda9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
3 changes: 3 additions & 0 deletions packages/webpack-plugin/lib/json-compiler/default-page.mpx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<view>局部构建兜底页面</view>
</template>
11 changes: 10 additions & 1 deletion packages/webpack-plugin/lib/json-compiler/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const parseRequest = require('../utils/parse-request')
const addQuery = require('../utils/add-query')
const loaderUtils = require('loader-utils')
const resolve = require('../utils/resolve')
const { RESOLVE_IGNORED_ERR } = require('../utils/const')

module.exports = function createJSONHelper ({ loaderContext, emitWarning, customGetDynamicEntry }) {
const mpx = loaderContext.getMpx()
Expand Down Expand Up @@ -101,7 +102,15 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning, custom
// 增加 page 标识
page = addQuery(page, { isPage: true })
resolve(context, page, loaderContext, (err, resource) => {
if (err) return callback(err)
if (err) {
if (err === RESOLVE_IGNORED_ERR && tarRoot) {
const defaultPage = require.resolve('./default-page.mpx') + `?resourcePath=${context}/${tarRoot}/pages/index.mpx`
resource = defaultPage
aliasPath = ''
} else {
return callback(err)
}
}
const { resourcePath, queryObj: { isFirst } } = parseRequest(resource)
const ext = path.extname(resourcePath)
let outputPath
Expand Down
8 changes: 3 additions & 5 deletions packages/webpack-plugin/lib/json-compiler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,12 +577,10 @@ module.exports = function (content) {
for (const root in subPackagesCfg) {
const subPackageCfg = subPackagesCfg[root]
// 分包不存在 pages,输出 subPackages 字段会报错
if (subPackageCfg.pages.length) {
if (!json.subPackages) {
json.subPackages = []
}
json.subPackages.push(subPackageCfg)
if (!json.subPackages) {
json.subPackages = []
}
json.subPackages.push(subPackageCfg)
}
const processOutput = (output) => {
output = processDynamicEntry(output)
Expand Down

0 comments on commit 664dda9

Please sign in to comment.