提交 4e7c0a5f 编写于 作者: fxy060608's avatar fxy060608

fix(h5): transform rpx when build (question/136238)

上级 0ca8e87e
...@@ -86,25 +86,21 @@ function registerGlobalCode(config: ResolvedConfig, ssr?: boolean) { ...@@ -86,25 +86,21 @@ function registerGlobalCode(config: ResolvedConfig, ssr?: boolean) {
const enableTreeShaking = isEnableTreeShaking( const enableTreeShaking = isEnableTreeShaking(
parseManifestJsonOnce(process.env.UNI_INPUT_DIR) parseManifestJsonOnce(process.env.UNI_INPUT_DIR)
) )
if (enableTreeShaking && config.command === 'build' && !ssr) { if (enableTreeShaking && config.command === 'build' && !ssr) {
// 非 SSR 的发行模式,补充全局 uni 对象 // 非 SSR 的发行模式,补充全局 uni 对象
return `${name}.uni = {};${name}.wx = {}` return `import { upx2px } from '@dcloudio/uni-h5';${name}.uni = {};${name}.wx = {};${name}.rpx2px = upx2px`
} }
const rpx2pxCode = return `
!ssr && config.define!.__UNI_FEATURE_RPX__ import {uni,upx2px,getCurrentPages,getApp,UniServiceJSBridge,UniViewJSBridge} from '@dcloudio/uni-h5'
? `import {upx2px} from '@dcloudio/uni-h5'
${name}.rpx2px = upx2px
`
: ''
return `${rpx2pxCode}
import {uni,getCurrentPages,getApp,UniServiceJSBridge,UniViewJSBridge} from '@dcloudio/uni-h5'
${name}.getApp = getApp ${name}.getApp = getApp
${name}.getCurrentPages = getCurrentPages ${name}.getCurrentPages = getCurrentPages
${name}.wx = uni ${name}.wx = uni
${name}.uni = uni ${name}.uni = uni
${name}.UniViewJSBridge = UniViewJSBridge ${name}.UniViewJSBridge = UniViewJSBridge
${name}.UniServiceJSBridge = UniServiceJSBridge ${name}.UniServiceJSBridge = UniServiceJSBridge
${name}.rpx2px = upx2px
${name}.__setupPage = (com)=>setupPage(com) ${name}.__setupPage = (com)=>setupPage(com)
` `
} }
......
...@@ -134,6 +134,8 @@ export function rewriteSsrResolve() { ...@@ -134,6 +134,8 @@ export function rewriteSsrResolve() {
return resolveBuiltIn(`@dcloudio/uni-h5-vue/dist/vue.runtime.cjs.js`) return resolveBuiltIn(`@dcloudio/uni-h5-vue/dist/vue.runtime.cjs.js`)
} else if (id === 'vue/package.json') { } else if (id === 'vue/package.json') {
return resolveBuiltIn(`@dcloudio/uni-h5-vue/package.json`) return resolveBuiltIn(`@dcloudio/uni-h5-vue/package.json`)
} else if (id === 'vue/server-renderer/package.json') {
return resolveBuiltIn(`@vue/server-renderer/package.json`)
} }
return oldSync(id, initResolveSyncOpts(opts)) return oldSync(id, initResolveSyncOpts(opts))
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册