头像太帅
头像太帅
  • 发布:2021-10-19 14:20
  • 更新:2022-02-10 11:48
  • 阅读:605

【报Bug】Vue3 自定义编译条件不生效,且报错

分类:uni-app

产品分类: uniapp/H5

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: w10

HBuilderX类型: 正式

HBuilderX版本号: 3.2.9

浏览器平台: Chrome

浏览器版本: 94

项目创建方式: HBuilderX

示例代码:

"uni-app": {
"scripts": {
"H5-dev": {
"title": "开发环境H5",
"env": {
"UNI_PLATFORM": "h5"
},
"define": {
"ENV-DEV": true
}
},
"mp-dingtalk": {
"title": "钉钉小程序",
"env": {
"UNI_PLATFORM": "mp-alipay"
},
"define": {
"MP-DINGTALK": true
}
}
}
}

// #ifndef ENV-DEV
console.log('ENV-DEV')
// #endif

操作步骤:

运行到自定义环境

预期结果:

不报错

实际结果:

14:18:49.274 2:18:48 ├F10: PM┤ [vite] Internal server error: ENV_DEV is not defined
14:18:49.274 Plugin: vite:uni-pre
14:18:49.276 File: D:/test/uniapp_vue3/hello/App.vue
14:18:49.277 at eval (eval at getTestTemplate (D:\Program Files\HBuilderX\plugins\uniapp-cli-vite\node_modules\@dcloudio\uni-cli-shared\lib\preprocess\lib\preprocess.js:381:10), <anonymous>:1:21)
14:18:49.279 at testPasses (D:\Program Files\HBuilderX\plugins\uniapp-cli-vite\node_modules\@dcloudio\uni-cli-shared\lib\preprocess\lib\preprocess.js:386:10)
14:18:49.280 at D:\Program Files\HBuilderX\plugins\uniapp-cli-vite\node_modules\@dcloudio\uni-cli-shared\lib\preprocess\lib\preprocess.js:186:19
14:18:49.282 at D:\Program Files\HBuilderX\plugins\uniapp-cli-vite\node_modules\@dcloudio\uni-cli-shared\lib\preprocess\lib\preprocess.js:332:22
14:18:49.282 at Array.reduce (<anonymous>)
14:18:49.285 at matchReplacePass (D:\Program Files\HBuilderX\plugins\uniapp-cli-vite\node_modules\@dcloudio\uni-cli-shared\lib\preprocess\lib\preprocess.js:319:20)
14:18:49.285 at replaceRecursive (D:\Program Files\HBuilderX\plugins\uniapp-cli-vite\node_modules\@dcloudio\uni-cli-shared\lib\preprocess\lib\preprocess.js:339:10)
14:18:49.289 at preprocessor (D:\Program Files\HBuilderX\plugins\uniapp-cli-vite\node_modules\@dcloudio\uni-cli-shared\lib\preprocess\lib\preprocess.js:164:10)
14:18:49.291 at preprocess (D:\Program Files\HBuilderX\plugins\uniapp-cli-vite\node_modules\@dcloudio\uni-cli-shared\lib\preprocess\lib\preprocess.js:89:10)
14:18:49.294 at Object.preJs (D:\Program Files\HBuilderX\plugins\uniapp-cli-vite\node_modules\@dcloudio\uni-cli-shared\dist\preprocess\index.js:10:12)
14:18:49.297 2:18:49 ├F10: PM┤ [vite] Internal server error: ENV_DEV is not defined
14:18:49.300 Plugin: vite:uni-pre
14:18:49.300 File: D:/test/uniapp_vue3/hello/App.vue
14:18:49.303 at eval (eval at getTestTemplate (D:\Program Files\HBuilderX\plugins\uniapp-cli-vite\node_modules\@dcloudio\uni-cli-shared\lib\preprocess\lib\preprocess.js:381:10), <anonymous>:1:21)
14:18:49.303 at testPasses (D:\Program Files\HBuilderX\plugins\uniapp-cli-vite\node_modules\@dcloudio\uni-cli-shared\lib\preprocess\lib\preprocess.js:386:10)
14:18:49.306 at D:\Program Files\HBuilderX\plugins\uniapp-cli-vite\node_modules\@dcloudio\uni-cli-shared\lib\preprocess\lib\preprocess.js:186:19
14:18:49.309 at D:\Program Files\HBuilderX\plugins\uniapp-cli-vite\node_modules\@dcloudio\uni-cli-shared\lib\preprocess\lib\preprocess.js:332:22
14:18:49.309 at Array.reduce (<anonymous>)
14:18:49.315 at matchReplacePass (D:\Program Files\HBuilderX\plugins\uniapp-cli-vite\node_modules\@dcloudio\uni-cli-shared\lib\preprocess\lib\preprocess.js:319:20)
14:18:49.316 at replaceRecursive (D:\Program Files\HBuilderX\plugins\uniapp-cli-vite\node_modules\@dcloudio\uni-cli-shared\lib\preprocess\lib\preprocess.js:339:10)
14:18:49.318 at preprocessor (D:\Program Files\HBuilderX\plugins\uniapp-cli-vite\node_modules\@dcloudio\uni-cli-shared\lib\preprocess\lib\preprocess.js:164:10)
14:18:49.321 at preprocess (D:\Program Files\HBuilderX\plugins\uniapp-cli-vite\node_modules\@dcloudio\uni-cli-shared\lib\preprocess\lib\preprocess.js:89:10)
14:18:49.324 at Object.preJs (D:\Program Files\HBuilderX\plugins\uniapp-cli-vite\node_modules\@dcloudio\uni-cli-shared\dist\preprocess\index.js:10:12) (x2)

bug描述:

Vue 3 自定义条件编译不生效

2021-10-19 14:20 负责人:无 分享
已邀请:
DCloud_UNI_Anne

DCloud_UNI_Anne

更新到HBuilderX 3.2.10 alpha 是否还存在此问题?

DCloud_UNI_Anne

DCloud_UNI_Anne

HBuilderX 3.3.11已修复

该问题目前已经被锁定, 无法添加新回复