diff --git a/packages/vue-cli-plugin-uni/lib/env.js b/packages/vue-cli-plugin-uni/lib/env.js index 0d7245450cef29cb240ab3e987845a4880886951..75eeca3216687c30f4c97bf0b9084af4b550d730 100644 --- a/packages/vue-cli-plugin-uni/lib/env.js +++ b/packages/vue-cli-plugin-uni/lib/env.js @@ -3,6 +3,12 @@ const path = require('path') const mkdirp = require('mkdirp') const loaderUtils = require('loader-utils') +const hasOwnProperty = Object.prototype.hasOwnProperty + +function hasOwn (obj, key) { + return hasOwnProperty.call(obj, key) +} + process.UNI_CLOUD = false process.UNI_CLOUD_TCB = false process.UNI_CLOUD_ALIYUN = false @@ -124,7 +130,7 @@ process.UNI_STAT_CONFIG = { // 默认启用 自定义组件模式 // if (isInHBuilderXAlpha) { let usingComponentsAbsent = false -if (!platformOptions.hasOwnProperty('usingComponents')) { +if (!hasOwn(platformOptions, 'usingComponents')) { usingComponentsAbsent = true } platformOptions.usingComponents = true @@ -173,12 +179,15 @@ if (process.env.UNI_PLATFORM === 'app-plus') { isNVueCompiler = false } if ( - platformOptions.compilerVersion === '3' || - platformOptions.compilerVersion === 3 + !hasOwn(platformOptions, 'compilerVersion') || // 默认v3 + ( + platformOptions.compilerVersion === '3' || + platformOptions.compilerVersion === 3 + ) ) { delete process.env.UNI_USING_CACHE if (platformOptions.renderer === 'native') { - process.env.UNI_USING_V3_NATIVE = true + process.env.UNI_USING_V3_NATIVE = true } else { process.env.UNI_USING_V3 = true platformOptions.usingComponents = true @@ -269,7 +278,8 @@ const needWarning = !platformOptions.usingComponents || usingComponentsAbsent let hasNVue = false // 输出编译器版本等信息 if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) { - console.log('当前nvue编译模式' + (process.env.UNI_USING_V3_NATIVE ? '(v3)' : '') + ':' + (isNVueCompiler ? 'uni-app' : 'weex') + + console.log('当前nvue编译模式' + (process.env.UNI_USING_V3_NATIVE ? '(v3)' : '') + ':' + (isNVueCompiler ? 'uni-app' + : 'weex') + ' 。编译模式差异见:https://ask.dcloud.net.cn/article/36074') } else if (process.env.UNI_PLATFORM !== 'h5' && process.env.UNI_PLATFORM !== 'quickapp') { try {