diff --git a/packages/global.d.ts b/packages/global.d.ts index 5a00c17fa8e..23f690a0701 100644 --- a/packages/global.d.ts +++ b/packages/global.d.ts @@ -41,6 +41,8 @@ declare var __PLUS__: boolean declare var __VUE_OPTIONS_API__: boolean declare var __VUE_PROD_DEVTOOLS__: boolean +declare var __UNI_FEATURE_VIRTUAL_HOST__: boolean +declare var __UNI_FEATURE_UCSS_RESET__: boolean declare var __UNI_FEATURE_WX__: boolean declare var __UNI_FEATURE_WXS__: boolean declare var __UNI_FEATURE_RPX__: boolean @@ -136,16 +138,16 @@ interface Uni { openDialogPage: (options: { url: string animationType?: - | 'auto' - | 'none' - | 'slide-in-right' - | 'slide-in-left' - | 'slide-in-top' - | 'slide-in-bottom' - | 'fade-in' - | 'zoom-out' - | 'zoom-fade-out' - | null + | 'auto' + | 'none' + | 'slide-in-right' + | 'slide-in-left' + | 'slide-in-top' + | 'slide-in-bottom' + | 'fade-in' + | 'zoom-out' + | 'zoom-fade-out' + | null animationDuration?: number | null disableEscBack?: boolean | null parentPage?: UniPage | null diff --git a/packages/uni-cli-shared/src/env/define.ts b/packages/uni-cli-shared/src/env/define.ts index 324b1599ea6..0cd676d14cb 100644 --- a/packages/uni-cli-shared/src/env/define.ts +++ b/packages/uni-cli-shared/src/env/define.ts @@ -6,9 +6,28 @@ export function initDefine(stringifyBoolean: boolean = false) { const platformManifestJson = getPlatformManifestJsonOnce() const isRunByHBuilderX = runByHBuilderX() const isDebug = !!manifestJson.debug + const isX = process.env.UNI_APP_X === 'true' + const isMP = process.env.UNI_PLATFORM.startsWith('mp') process.env['UNI_APP_ID'] = manifestJson.appid + let mpXDefine = + isX && isMP + ? { + __UNI_FEATURE_UCSS_RESET__: true, + __UNI_FEATURE_VIRTUAL_HOST__: true, + } + : { + __UNI_FEATURE_UCSS_RESET__: false, + __UNI_FEATURE_VIRTUAL_HOST__: false, + } + if (isX && isMP) { + mpXDefine.__UNI_FEATURE_UCSS_RESET__ = + platformManifestJson.enableUcssReset !== false + mpXDefine.__UNI_FEATURE_VIRTUAL_HOST__ = + platformManifestJson.enableVirtualHost !== false + } + return { ...initCustomDefine(), 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV), @@ -58,6 +77,7 @@ export function initDefine(stringifyBoolean: boolean = false) { 'process.env.VUE_APP_DARK_MODE': JSON.stringify( platformManifestJson.darkmode || false ), + ...mpXDefine, } } diff --git a/packages/uni-cli-shared/src/json/mp/pages.ts b/packages/uni-cli-shared/src/json/mp/pages.ts index 0bd1a6f4b27..1933c160ae7 100644 --- a/packages/uni-cli-shared/src/json/mp/pages.ts +++ b/packages/uni-cli-shared/src/json/mp/pages.ts @@ -42,6 +42,8 @@ const NON_APP_JSON_KEYS = [ 'uniStatistics', 'mergeVirtualHostAttributes', 'styleIsolation', + 'enableVirtualHost', + 'enableUcssReset', ] export function mergeMiniProgramAppJson( diff --git a/packages/uni-mp-core/src/runtime/component.ts b/packages/uni-mp-core/src/runtime/component.ts index edd43fef058..5c96a7c0043 100644 --- a/packages/uni-mp-core/src/runtime/component.ts +++ b/packages/uni-mp-core/src/runtime/component.ts @@ -106,7 +106,7 @@ export function parseComponent( pureDataPattern: /^uP$/, } - if (__X__ && __PLATFORM__ === 'mp-weixin' && !isPageInProject) { + if (__X__ && __UNI_FEATURE_VIRTUAL_HOST__ && !isPageInProject) { options.virtualHost = true } diff --git a/packages/uni-mp-vite/src/plugin/index.ts b/packages/uni-mp-vite/src/plugin/index.ts index 8a10e506585..cf33fad2845 100644 --- a/packages/uni-mp-vite/src/plugin/index.ts +++ b/packages/uni-mp-vite/src/plugin/index.ts @@ -248,6 +248,10 @@ export function uniMiniProgramPlugin( } export function genUVueCssCode(manifestJson: Record) { + const platformConfig = manifestJson[process.env.UNI_PLATFORM] || {} + if (platformConfig.enableUcssReset === false) { + return '' + } let cssCode = fs.readFileSync( path.resolve(__dirname, '../../lib/uvue.css'), 'utf8' diff --git a/packages/uni-mp-vite/src/plugin/uni/index.ts b/packages/uni-mp-vite/src/plugin/uni/index.ts index e455486be77..e052f8e9926 100644 --- a/packages/uni-mp-vite/src/plugin/uni/index.ts +++ b/packages/uni-mp-vite/src/plugin/uni/index.ts @@ -29,12 +29,11 @@ export function uniOptions({ }): UniVitePlugin['uni'] { const manifest = parseManifestJsonOnce(process.env.UNI_INPUT_DIR) const platformOptions = manifest[process.env.UNI_PLATFORM] || {} - + const isX = process.env.UNI_APP_X === 'true' const mergeVirtualHostAttributes = platformOptions.mergeVirtualHostAttributes != null ? platformOptions.mergeVirtualHostAttributes - : process.env.UNI_PLATFORM === 'mp-weixin' && - process.env.UNI_APP_X === 'true' + : isX return { copyOptions, @@ -46,10 +45,7 @@ export function uniOptions({ mergeVirtualHostAttributes, }), }), - isNativeTag: - process.env.UNI_APP_X === 'true' - ? isMiniProgramUVueNativeTag - : isMiniProgramNativeTag, + isNativeTag: isX ? isMiniProgramUVueNativeTag : isMiniProgramNativeTag, isCustomElement: createIsCustomElement(customElements), ...compilerOptions, nodeTransforms: [