diff --git a/packages/uni-cli-shared/lib/preprocess.js b/packages/uni-cli-shared/lib/preprocess.js index 46faf009a8db104ab62c8b68457f36db7956fce3..861cd65b7e3bc19c3899be92eb0c8975d849be22 100644 --- a/packages/uni-cli-shared/lib/preprocess.js +++ b/packages/uni-cli-shared/lib/preprocess.js @@ -5,7 +5,10 @@ const DEFAULT_KEYS = [ 'APP', 'APP-PLUS-NVUE', 'APP-VUE', - 'APP-NVUE' + 'APP-NVUE', + 'APP-ANDROID', + 'APP-IOS', + 'WEB' ] function normalize (name) { @@ -44,14 +47,25 @@ module.exports = function initPreprocess (name, platforms, userDefines = {}) { nvueContext.APP_PLUS = true nvueContext.APP_NVUE = true nvueContext.APP_PLUS_NVUE = true - } + if (process.env.UNI_APP_PLATFORM === 'android') { + defaultContext.APP_ANDROID = true + } else if (process.env.UNI_APP_PLATFORM === 'ios') { + defaultContext.APP_IOS = true + } else { + defaultContext.APP_ANDROID = true + defaultContext.APP_IOS = true + } + } + if (name === 'h5') { + defaultContext.WEB = true + } if (name.startsWith('mp-')) { vueContext.MP = true } if (name.startsWith('app-')) { - vueContext.APP = true + vueContext.APP = true nvueContext.APP = true } diff --git a/packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js b/packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js index 14c71afe5709b0240c209b9bdfdc88bc0c2e2102..8d16912de32c6bb61b45c41ab04c86734c5c36d6 100644 --- a/packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js +++ b/packages/uni-template-compiler/__tests__/compiler-mp-alipay.spec.js @@ -31,11 +31,11 @@ describe('mp:compiler-mp-alipay', () => { it('generate ref', () => { assertCodegen( 'text', - 'text' + 'text' ) assertCodegen( 'text123213', - 'text123213' + 'text123213' ) assertCodegen( '', @@ -47,7 +47,7 @@ describe('mp:compiler-mp-alipay', () => { ) assertCodegen( 'text', - 'text', + 'text', undefined, undefined, { @@ -56,7 +56,7 @@ describe('mp:compiler-mp-alipay', () => { ) assertCodegen( 'text', - 'text', + 'text', undefined, undefined, { @@ -65,7 +65,7 @@ describe('mp:compiler-mp-alipay', () => { ) assertCodegen( 'text', - 'text', + 'text', undefined, undefined, { @@ -82,33 +82,33 @@ describe('mp:compiler-mp-alipay', () => { it('generate default slot', () => { assertCodegen( 'text', - 'text' + 'text' ) assertCodegen( 'text123213', - 'text123213' + 'text123213' ) assertCodegen( 'text', - 'text' + 'text' ) }) it('generate scoped slot', () => { assertCodegen( '', - '{{props.text}}' + '{{props.text}}' ) assertCodegen( '', - '{{__SCOPED__.text}}' + '{{__SCOPED__.text}}' ) }) it('generate scoped slot with scopedSlotsCompiler: auto', () => { assertCodegen( '