Skip to content

Commit 74ab2e7

Browse files
committed
chore(dom2): 调整部分 dom2 判断
1 parent 620e62f commit 74ab2e7

File tree

5 files changed

+13
-26
lines changed

5 files changed

+13
-26
lines changed

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ 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 isDom2 = process.env.UNI_APP_X_DOM2 === 'true'
38+
const isDom2Harmony = isDom2 && process.env.UNI_UTS_PLATFORM === 'app-harmony'
3739
return {
3840
name,
3941
// 需要提前,因为unocss会在configResolved读取vite:css-post插件
@@ -69,9 +71,6 @@ export function uniAppCssPrePlugin(): Plugin {
6971
platform: process.env.UNI_UTS_PLATFORM,
7072
helper: requireUniHelpers(),
7173
})
72-
const isDom2Harmony =
73-
process.env.UNI_APP_X_DOM2 === 'true' &&
74-
process.env.UNI_UTS_PLATFORM === 'app-harmony'
7574
if (isDom2Harmony && fontFaces) {
7675
const id = CSS_FILE_ID_MAP.get(filename)
7776
if (id) {
@@ -121,10 +120,6 @@ export function uniAppCssPrePlugin(): Plugin {
121120
name: 'uni:app-uvue-css-inline-post',
122121
apply: 'build',
123122
generateBundle(_, bundle) {
124-
// 暂时保留此条件容错
125-
const isDom2Harmony =
126-
process.env.UNI_APP_X_DOM2 === 'true' &&
127-
process.env.UNI_UTS_PLATFORM === 'app-harmony'
128123
if (isDom2Harmony) {
129124
Object.entries(bundle).forEach(([file, asset]) => {
130125
// 不支持多style标签
@@ -158,9 +153,6 @@ export function uniAppCssPrePlugin(): Plugin {
158153
// 重要:必须放到 unplugin-auto-import、uni:sd 前
159154
const index = plugins.findIndex((p) => p.name === 'unplugin-auto-import')
160155
plugins.splice(index, 0, uvueCssPostPlugin)
161-
const isDom2Harmony =
162-
process.env.UNI_APP_X_DOM2 === 'true' &&
163-
process.env.UNI_UTS_PLATFORM === 'app-harmony'
164156
if (isDom2Harmony) {
165157
plugins.splice(index + 1, 0, uvueCssInlinePostPlugin)
166158
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ export function init() {
7676
},
7777
},
7878
}),
79-
...(process.env.UNI_APP_X_DOM2 === 'true' ? [uniSharedDataPlugin()] : []),
79+
...(isDom2 ? [uniSharedDataPlugin()] : []),
8080
...(process.env.UNI_COMPILE_EXT_API_TYPE === 'pages'
8181
? [replaceExtApiPagePaths()]
8282
: []),
83-
...(process.env.UNI_APP_X_DOM2 === 'true' ? [uniAppCssPlugin()] : []),
83+
...(isDom2 ? [uniAppCssPlugin()] : []),
8484
...(isNormalCompileTarget() ? [uniStatsPlugin()] : []),
8585
]
8686
}

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

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

89+
const isDom2 = process.env.UNI_APP_X_DOM2 === 'true'
8990
return {
9091
name: 'uni:app-uts',
9192
apply: 'build',
@@ -166,16 +167,13 @@ export function createUniAppJsEnginePlugin(
166167
},
167168
configResolved(config) {
168169
configResolved(config)
169-
if (process.env.UNI_APP_X_DOM2 !== 'true') {
170+
if (!isDom2) {
170171
initUniAppJsEngineDom1CssPlugin(config)
171172
}
172173
insertBeforePlugin(uniAppJsPlugin(config), 'uni:app-main', config)
173174
// 如果开启了 vapor 模式,则禁用 vue 的 devtools,让 @vitejs/plugin-vue 不管是开发还是发行,均生成发行代码
174175
// 理论上非 vapor 也应该禁用,但为了不引发其他问题,暂时只禁用 vapor 模式
175-
if (
176-
process.env.UNI_VUE_VAPOR === 'true' ||
177-
process.env.UNI_APP_X_DOM2 === 'true'
178-
) {
176+
if (isDom2 || process.env.UNI_VUE_VAPOR === 'true') {
179177
const plugin = config.plugins.find((p) => p.name === 'vite:vue')
180178
if (plugin?.api?.options) {
181179
plugin.api.options.devToolsEnabled = false

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,9 @@ const isXHarmony =
3535
export function createUniOptions(
3636
platform: 'app-android' | 'app-ios' | 'app-harmony'
3737
): UniVitePlugin['uni'] {
38+
const isDom2 = process.env.UNI_APP_X_DOM2 === 'true'
3839
return {
39-
compiler:
40-
process.env.UNI_APP_X_DOM2 === 'true'
41-
? require('@dcloudio/compiler-vapor-dom2')
42-
: undefined,
40+
compiler: isDom2 ? require('@dcloudio/compiler-vapor-dom2') : undefined,
4341
copyOptions() {
4442
const inputDir = process.env.UNI_INPUT_DIR
4543
const outputDir = process.env.UNI_OUTPUT_DIR
@@ -74,7 +72,7 @@ export function createUniOptions(
7472
platform === 'app-ios' || platform === 'app-harmony'
7573
? {
7674
isNativeTag(tag) {
77-
if (process.env.UNI_APP_X_DOM2 === 'true') {
75+
if (isDom2) {
7876
return isDom2AppNativeTag(tag)
7977
}
8078
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,6 +386,8 @@ 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'
389391
return {
390392
name: 'vite:css-post',
391393
buildStart() {
@@ -401,9 +403,6 @@ export function cssPostPlugin(
401403

402404
// build CSS handling ----------------------------------------------------
403405
styles.set(id, css)
404-
const isDom2Harmony =
405-
process.env.UNI_APP_X_DOM2 === 'true' &&
406-
process.env.UNI_UTS_PLATFORM === 'app-harmony'
407406
return {
408407
code:
409408
modulesCode ||
@@ -419,7 +418,7 @@ export function cssPostPlugin(
419418
}
420419
},
421420
async renderChunk(_code, chunk, _opts) {
422-
if (platform === 'app-harmony' && process.env.UNI_APP_X_DOM2 === 'true') {
421+
if (isDom2Harmony) {
423422
// 通过 generateBundle 实现
424423
return null
425424
}

0 commit comments

Comments
 (0)