提交 57c54d96 编写于 作者: Y yurj26

fix(mp-weixin): styleIsolation兼容glass-easel框架 (question/178062)

上级 c1f58e38
......@@ -153,7 +153,16 @@ function updateUsingAutoImportComponents (name, usingAutoImportComponents) {
}
}
function updateUsingComponents (name, usingComponents, type) {
const styleIsolationRE =
/export\s+default\s+[\s\S]*?styleIsolation\s*:\s*['|"](isolated|apply-shared|shared)['|"]/
function parseComponentStyleIsolation (content) {
const matches = content.match(styleIsolationRE)
if (matches) {
return matches[1]
}
}
function updateUsingComponents (name, usingComponents, type, content = '') {
if (type === 'Component') {
componentSet.add(name)
}
......@@ -168,9 +177,21 @@ function updateUsingComponents (name, usingComponents, type) {
if (type === 'Component') {
jsonObj.component = true
if (process.env.UNI_PLATFORM === 'mp-alipay') {
const manifestConfig = process.UNI_MANIFEST
const alipayConfig = manifestConfig['mp-alipay'] || {}
jsonObj.styleIsolation = alipayConfig.styleIsolation || 'apply-shared'
const alipayConfig = process.UNI_MANIFEST['mp-alipay'] || {}
jsonObj.styleIsolation =
parseComponentStyleIsolation(content) ||
alipayConfig.styleIsolation ||
'apply-shared'
}
// 微信小程序json文件中的styleIsolation优先级比options中的高,为了兼容旧版本,不能设置默认值,并且只有在manifest.json中配置styleIsolation才会静态分析组件的styleIsolation
if (process.env.UNI_PLATFORM === 'mp-weixin') {
const weixinConfig = process.UNI_MANIFEST['mp-weixin'] || {}
if (weixinConfig.styleIsolation) {
jsonObj.styleIsolation =
parseComponentStyleIsolation(content) ||
weixinConfig.styleIsolation
}
}
} else if (type === 'Page') {
if (process.env.UNI_PLATFORM === 'mp-baidu') {
......
......@@ -101,7 +101,7 @@ module.exports = function (content, map) {
return
}
// 防止组件从有到无,App.vue 中不支持使用组件
updateUsingComponents(resourcePath, Object.create(null), type)
updateUsingComponents(resourcePath, Object.create(null), type, content)
callback(null, content, map)
return
}
......@@ -148,7 +148,7 @@ module.exports = function (content, map) {
}
addDynamicImport(babelLoader, resourcePath, dynamicImports)
updateUsingComponents(resourcePath, usingComponents, type)
updateUsingComponents(resourcePath, usingComponents, type, content)
callback(null, content, map)
}
}, err => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册