Skip to content

Commit

Permalink
fix: processShowStyle 添加是否为 virtualHost 的判断
Browse files Browse the repository at this point in the history
  • Loading branch information
Blackgan3 committed Dec 23, 2024
1 parent f9a64b4 commit b058934
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
6 changes: 5 additions & 1 deletion packages/webpack-plugin/lib/template-compiler/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2189,6 +2189,10 @@ function isComponentNode (el, options) {
return usingComponents.indexOf(el.tag) !== -1 || el.tag === 'component'
}

function isVirtualHostNode (el, options) {
return options.usingComponentsInfo[el.tag]?.hvh
}

function isReactComponent (el, options) {
return !isComponentNode(el, options) && isRealNode(el) && !el.isBuiltIn
}
Expand Down Expand Up @@ -2416,7 +2420,7 @@ function processShow (el, options, root) {
show = has ? `{{${parseMustacheWithContext(show).result}&&mpxShow}}` : '{{mpxShow}}'
}
if (show === undefined) return
if (isComponentNode(el, options)) {
if (isComponentNode(el, options) && isVirtualHostNode(el, options)) {
if (show === '') {
show = '{{false}}'
}
Expand Down
14 changes: 9 additions & 5 deletions packages/webpack-plugin/lib/utils/pre-process-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const addQuery = require('./add-query')
const resolve = require('./resolve')
const getJSONContent = require('./get-json-content')
const getRulesRunner = require('../platform')
const { matchCondition } = require('./match-condition')
const async = require('async')

module.exports = function ({
Expand All @@ -19,8 +20,7 @@ module.exports = function ({
}, callback) {
const mpx = loaderContext.getMpx()
const context = loaderContext.context
const mode = mpx.mode
const pagesMap = mpx.pagesMap
const { mode, pagesMap, autoVirtualHostRules } = mpx
async.waterfall([
(callback) => {
getJSONContent(json, null, loaderContext, callback)
Expand Down Expand Up @@ -78,8 +78,11 @@ module.exports = function ({
componentGenerics = Object.assign({}, ret.componentGenerics)
}
if (usingComponents) {
const setUsingComponentInfo = (name, moduleId) => {
usingComponentsInfo[name] = { mid: moduleId }
const setUsingComponentInfo = (name, moduleId, hasVirtualHost) => {
usingComponentsInfo[name] = {
mid: moduleId,
hvh: hasVirtualHost
}
}
async.eachOf(usingComponents, (component, name, callback) => {
if (ctorType === 'app') {
Expand All @@ -96,7 +99,8 @@ module.exports = function ({
if (err) return callback(err)
const { rawResourcePath } = parseRequest(resource)
const moduleId = mpx.getModuleId(rawResourcePath, ctorType === 'app')
setUsingComponentInfo(name, moduleId)
const hasVirtualHost = matchCondition(rawResourcePath, autoVirtualHostRules)
setUsingComponentInfo(name, moduleId, hasVirtualHost)
callback()
})
}, (err) => {
Expand Down

0 comments on commit b058934

Please sign in to comment.