Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: processShowStyle 添加是否为 virtualHost 的判断 #1777

Merged
merged 4 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Blackgan3 marked this conversation as resolved.
Show resolved Hide resolved
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) => {
Blackgan3 marked this conversation as resolved.
Show resolved Hide resolved
usingComponentsInfo[name] = {
mid: moduleId,
hvh: hasVirtualHost
Blackgan3 marked this conversation as resolved.
Show resolved Hide resolved
}
}
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
Loading