Skip to content

Commit 1ebada6

Browse files
committed
wip(x-ios): 调整部分dom2判断条件
1 parent 8c19961 commit 1ebada6

File tree

8 files changed

+27
-43
lines changed

8 files changed

+27
-43
lines changed

packages/uni-app-uts/src/plugins/dom2/css.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ export function uniAppCssPrePlugin(): Plugin {
3434
const mainPath = resolveMainPathOnce(process.env.UNI_INPUT_DIR)
3535
const appUVuePath = resolveAppVue(process.env.UNI_INPUT_DIR)
3636
const { parseCss } = require('@dcloudio/compiler-vapor-dom2')
37-
const isDom2Harmony =
38-
process.env.UNI_APP_X_DOM2 === 'true' &&
39-
process.env.UNI_UTS_PLATFORM === 'app-harmony'
37+
const isDom2 = process.env.UNI_APP_X_DOM2 === 'true'
4038
return {
4139
name,
4240
// 需要提前,因为unocss会在configResolved读取vite:css-post插件
@@ -72,7 +70,7 @@ export function uniAppCssPrePlugin(): Plugin {
7270
platform: process.env.UNI_UTS_PLATFORM,
7371
helper: requireUniHelpers(),
7472
})
75-
if (isDom2Harmony && fontFaces) {
73+
if (isDom2 && fontFaces) {
7674
const id = CSS_FILE_ID_MAP.get(filename)
7775
if (id) {
7876
const cloneFontFaces = fontFaces.reduce(
@@ -121,7 +119,7 @@ export function uniAppCssPrePlugin(): Plugin {
121119
name: 'uni:app-uvue-css-inline-post',
122120
apply: 'build',
123121
generateBundle(_, bundle) {
124-
if (isDom2Harmony) {
122+
if (isDom2) {
125123
Object.entries(bundle).forEach(([file, asset]) => {
126124
// 不支持多style标签
127125
if (asset.type === 'chunk') {
@@ -154,7 +152,7 @@ export function uniAppCssPrePlugin(): Plugin {
154152
// 重要:必须放到 unplugin-auto-import、uni:sd 前
155153
const index = plugins.findIndex((p) => p.name === 'unplugin-auto-import')
156154
plugins.splice(index, 0, uvueCssPostPlugin)
157-
if (isDom2Harmony) {
155+
if (isDom2) {
158156
plugins.splice(index + 1, 0, uvueCssInlinePostPlugin)
159157
}
160158
},

packages/uni-app-uts/src/plugins/harmony/index.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,9 @@ import { replaceExtApiPagePaths } from '../js/extApiPages'
2929
import { uniAppCssPlugin, uniAppCssPrePlugin } from '../dom2/css'
3030

3131
export function init() {
32-
const isDom2Harmony =
33-
process.env.UNI_APP_X_DOM2 === 'true' &&
34-
process.env.UNI_UTS_PLATFORM === 'app-harmony'
32+
const isDom2 = process.env.UNI_APP_X_DOM2 === 'true'
3533
return [
36-
...(isDom2Harmony ? [uniAppCssPrePlugin()] : []),
34+
...(isDom2 ? [uniAppCssPrePlugin()] : []),
3735
...(isNormalCompileTarget()
3836
? [uniWorkersPlugin(), uniDecryptUniModulesPlugin()]
3937
: []),
@@ -60,13 +58,13 @@ export function init() {
6058
]),
6159
uniUTSUVueJavaScriptPlugin(),
6260
resolveUTSCompiler().uts2js({
63-
dom2: isDom2Harmony,
61+
dom2: isDom2,
6462
platform: 'app-harmony',
6563
inputDir: process.env.UNI_INPUT_DIR,
6664
version: process.env.UNI_COMPILER_VERSION,
6765
cacheRoot: path.resolve(process.env.UNI_APP_X_CACHE_DIR, '.uts2js/cache'),
6866
sourceMap: enableSourceMap(),
69-
sharedDataLibName: isDom2Harmony ? 'libentry.so' : undefined,
67+
sharedDataLibName: isDom2 ? 'libentry.so' : undefined,
7068
modules: {
7169
vueCompilerDom,
7270
uniCliShared,
@@ -78,11 +76,11 @@ export function init() {
7876
},
7977
},
8078
}),
81-
...(isDom2Harmony ? [uniSharedDataPlugin()] : []),
79+
...(isDom2 ? [uniSharedDataPlugin()] : []),
8280
...(process.env.UNI_COMPILE_EXT_API_TYPE === 'pages'
8381
? [replaceExtApiPagePaths()]
8482
: []),
85-
...(isDom2Harmony ? [uniAppCssPlugin()] : []),
83+
...(isDom2 ? [uniAppCssPlugin()] : []),
8684
...(isNormalCompileTarget() ? [uniStatsPlugin()] : []),
8785
]
8886
}

packages/uni-app-uts/src/plugins/js/pagesJson.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ export function uniAppPagesPlugin(): Plugin {
2626
PAGES_JSON_UTS
2727
)
2828

29-
const isDom2Harmony =
30-
process.env.UNI_APP_X_DOM2 === 'true' &&
31-
process.env.UNI_UTS_PLATFORM === 'app-harmony'
29+
const isDom2 = process.env.UNI_APP_X_DOM2 === 'true'
3230

3331
let allPagePaths: string[] = []
3432
let isFirst = true
@@ -83,7 +81,7 @@ export function uniAppPagesPlugin(): Plugin {
8381
const pagesJson = normalizeUniAppXAppPagesJson(code)
8482

8583
// vapor 暂不支持 tabBar
86-
if (isDom2Harmony) {
84+
if (isDom2) {
8785
if (pagesJson.tabBar) {
8886
hasTabBar = true
8987
delete pagesJson.tabBar

packages/uni-app-uts/src/plugins/js/plugin.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,7 @@ export function createUniAppJsEnginePlugin(
8686
}
8787
: {}
8888

89-
const isDom2Harmony =
90-
process.env.UNI_APP_X_DOM2 === 'true' &&
91-
process.env.UNI_UTS_PLATFORM === 'app-harmony'
89+
const isDom2 = process.env.UNI_APP_X_DOM2 === 'true'
9290
return {
9391
name: 'uni:app-uts',
9492
apply: 'build',
@@ -172,13 +170,13 @@ export function createUniAppJsEnginePlugin(
172170
},
173171
configResolved(config) {
174172
configResolved(config)
175-
if (!isDom2Harmony) {
173+
if (!isDom2) {
176174
initUniAppJsEngineDom1CssPlugin(config)
177175
}
178176
insertBeforePlugin(uniAppJsPlugin(config), 'uni:app-main', config)
179177
// 如果开启了 vapor 模式,则禁用 vue 的 devtools,让 @vitejs/plugin-vue 不管是开发还是发行,均生成发行代码
180178
// 理论上非 vapor 也应该禁用,但为了不引发其他问题,暂时只禁用 vapor 模式
181-
if (isDom2Harmony) {
179+
if (isDom2) {
182180
const plugin = config.plugins.find((p) => p.name === 'vite:vue')
183181
if (plugin?.api?.options) {
184182
plugin.api.options.devToolsEnabled = false

packages/uni-app-uts/src/plugins/utils.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,9 @@ const isXHarmony =
3535
export function createUniOptions(
3636
platform: 'app-android' | 'app-ios' | 'app-harmony'
3737
): UniVitePlugin['uni'] {
38-
const isDom2Harmony =
39-
process.env.UNI_APP_X_DOM2 === 'true' && platform === 'app-harmony'
38+
const isDom2 = process.env.UNI_APP_X_DOM2 === 'true'
4039
return {
41-
compiler: isDom2Harmony
42-
? require('@dcloudio/compiler-vapor-dom2')
43-
: undefined,
40+
compiler: isDom2 ? require('@dcloudio/compiler-vapor-dom2') : undefined,
4441
copyOptions() {
4542
const inputDir = process.env.UNI_INPUT_DIR
4643
const outputDir = process.env.UNI_OUTPUT_DIR
@@ -75,7 +72,7 @@ export function createUniOptions(
7572
platform === 'app-ios' || platform === 'app-harmony'
7673
? {
7774
isNativeTag(tag) {
78-
if (isDom2Harmony) {
75+
if (isDom2) {
7976
return isDom2AppNativeTag(tag)
8077
}
8178
return (

packages/uni-cli-shared/src/vite/plugins/vitejs/plugins/css.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,7 @@ export function cssPostPlugin(
386386
// styles initialization in buildStart causes a styling loss in watch
387387
const styles: Map<string, string> = new Map<string, string>()
388388
let cssChunks: Map<string, string[]>
389-
const isDom2Harmony =
390-
process.env.UNI_APP_X_DOM2 === 'true' && platform === 'app-harmony'
389+
const isDom2 = process.env.UNI_APP_X_DOM2 === 'true'
391390
return {
392391
name: 'vite:css-post',
393392
buildStart() {
@@ -407,7 +406,7 @@ export function cssPostPlugin(
407406
code:
408407
modulesCode ||
409408
(isJsCode
410-
? isDom2Harmony
409+
? isDom2
411410
? `export default ${JS_STYLE_PLACEHOLDER_STR}`
412411
: 'export default {}'
413412
: ''),
@@ -418,7 +417,7 @@ export function cssPostPlugin(
418417
}
419418
},
420419
async renderChunk(_code, chunk, _opts) {
421-
if (isDom2Harmony) {
420+
if (isDom2) {
422421
// 通过 generateBundle 实现
423422
return null
424423
}

packages/vite-plugin-uni/src/plugins/copy.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ export function uniCopyPlugin({
2222
}: Pick<VitePluginUniResolvedOptions, 'outputDir' | 'copyOptions'>): Plugin {
2323
const staticDir = PUBLIC_DIR + '/**/*'
2424
const uniModulesStaticDir = 'uni_modules/*/' + PUBLIC_DIR + '/**/*'
25-
const isDom2Harmony =
26-
process.env.UNI_APP_X_DOM2 === 'true' &&
27-
process.env.UNI_PLATFORM === 'app-harmony'
28-
const uniModulesCppDir = isDom2Harmony ? 'uni_modules/*/cppsdk/**/*' : ''
25+
const isDom2 = process.env.UNI_APP_X_DOM2 === 'true'
26+
const uniModulesCppDir = isDom2 ? 'uni_modules/*/cppsdk/**/*' : ''
2927
const assets = [staticDir, uniModulesStaticDir]
3028
const cppAssets: string[] = []
3129
if (uniModulesCppDir) {

packages/vite-plugin-uni/src/vue/options.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,10 @@ export function initPluginVueOptions(
9696
const compilerOptions =
9797
templateOptions.compilerOptions || (templateOptions.compilerOptions = {})
9898

99-
const isDom2Harmony =
100-
process.env.UNI_APP_X_DOM2 === 'true' &&
101-
process.env.UNI_PLATFORM === 'app-harmony'
99+
const isDom2 = process.env.UNI_APP_X_DOM2 === 'true'
102100

103101
;(compilerOptions as any).isX = process.env.UNI_APP_X === 'true'
104-
;(compilerOptions as any).dom2 = isDom2Harmony
102+
;(compilerOptions as any).dom2 = isDom2
105103

106104
// 默认就移除comments节点
107105
compilerOptions.comments = false
@@ -224,7 +222,7 @@ export function initPluginVueOptions(
224222
compilerOptions.nodeTransforms.push(
225223
...getBaseNodeTransforms(
226224
options.base,
227-
isDom2Harmony ? createResolveStaticAsset(options.inputDir) : undefined
225+
isDom2 ? createResolveStaticAsset(options.inputDir) : undefined
228226
)
229227
)
230228
}
@@ -308,7 +306,7 @@ export function initPluginVueOptions(
308306
if (!vueOptions.script.babelParserPlugins.includes('decorators')) {
309307
vueOptions.script.babelParserPlugins.push('decorators')
310308
}
311-
if (isDom2Harmony) {
309+
if (isDom2) {
312310
const appVue = resolveAppVue(process.env.UNI_INPUT_DIR)
313311
function isAppVue(id: string) {
314312
return normalizePath(id) === appVue

0 commit comments

Comments
 (0)