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

feat: add api.json

上级 9ce85c2c
此差异已折叠。
......@@ -14,7 +14,11 @@ export default {
title: 'Hello',
}
},
onLoad() {},
onLoad() {
// 测试API摇树
console.log(uni.report)
console.log(uni.upx2px)
},
methods: {},
}
</script>
......
......@@ -45,3 +45,5 @@ export * from './ad/rewardedVideoAd'
export * from './ad/fullScreenVideoAd'
export * from './ad/interstitialAd'
export * from './ad/interactiveAd'
export * from './route/navigateTo'
......@@ -123,7 +123,16 @@ export function uniViteInjectPlugin(options: InjectOptions): Plugin {
if (mods.length === 2) {
mod = namespaceModulesMap.get(mods[0] + '.')
if (mod) {
mod = [mod as string, mods[1]]
if (Array.isArray(mod)) {
const testFn = mod[1] as unknown as (method: string) => boolean
if (testFn(mods[1])) {
mod = [mod[0], mods[1]]
} else {
mod = undefined
}
} else {
mod = [mod, mods[1]]
}
}
}
}
......
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.uniInjectPlugin = void 0;
const path_1 = __importDefault(require("path"));
const shared_1 = require("@vue/shared");
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
const apiJson = require(path_1.default.resolve(__dirname, '../../lib/api.json'));
const uniInjectPluginOptions = {
exclude: [...uni_cli_shared_1.COMMON_EXCLUDE],
'uni.': '@dcloudio/uni-h5',
'uni.': [
'@dcloudio/uni-h5',
((method) => apiJson.includes(method)),
],
getApp: ['@dcloudio/uni-h5', 'getApp'],
getCurrentPages: ['@dcloudio/uni-h5', 'getCurrentPages'],
UniServiceJSBridge: ['@dcloudio/uni-h5', 'UniServiceJSBridge'],
......
......@@ -17,10 +17,8 @@ function uniPagesJsonPlugin() {
if (opts.filter(id)) {
const { resolvedConfig } = opts;
return {
code: (resolvedConfig.command === 'serve' ||
(resolvedConfig.command === 'build' && ssr)
? registerGlobalCode(resolvedConfig, ssr)
: '') + generatePagesJsonCode(ssr, code, resolvedConfig),
code: registerGlobalCode(resolvedConfig, ssr) +
generatePagesJsonCode(ssr, code, resolvedConfig),
map: { mappings: '' },
};
}
......@@ -63,6 +61,10 @@ function getGlobal(ssr) {
}
function registerGlobalCode(config, ssr) {
const name = getGlobal(ssr);
if (config.command === 'build' && !ssr) {
// 非SSR的发行模式,补充全局 uni 对象
return `${name}.uni = {}`;
}
const rpx2pxCode = !ssr && config.define.__UNI_FEATURE_RPX__
? `import {upx2px} from '@dcloudio/uni-h5'
${name}.rpx2px = upx2px
......
[
"$emit",
"$off",
"$on",
"$once",
"addInterceptor",
"addPhoneContact",
"arrayBufferToBase64",
"base64ToArrayBuffer",
"canIUse",
"canvasGetImageData",
"canvasPutImageData",
"canvasToTempFilePath",
"chooseFile",
"chooseImage",
"chooseLocation",
"chooseVideo",
"clearStorage",
"clearStorageSync",
"closeSocket",
"connectSocket",
"createAnimation",
"createCameraContext",
"createCanvasContext",
"createInnerAudioContext",
"createIntersectionObserver",
"createLivePlayerContext",
"createMapContext",
"createMediaQueryObserver",
"createSelectorQuery",
"createVideoContext",
"downloadFile",
"getFileInfo",
"getImageInfo",
"getLeftWindowStyle",
"getLocation",
"getNetworkType",
"getProvider",
"getRealPath",
"getRecorderManager",
"getRightWindowStyle",
"getSavedFileInfo",
"getSavedFileList",
"getScreenBrightness",
"getSelectedTextRange",
"getStorage",
"getStorageInfo",
"getStorageInfoSync",
"getStorageSync",
"getSystemInfo",
"getSystemInfoSync",
"getTopWindowStyle",
"getVideoInfo",
"hideKeyboard",
"hideLeftWindow",
"hideLoading",
"hideNavigationBarLoading",
"hideRightWindow",
"hideTabBar",
"hideTabBarRedDot",
"hideToast",
"hideTopWindow",
"loadFontFace",
"login",
"makePhoneCall",
"navigateBack",
"navigateTo",
"offAccelerometerChange",
"offCompassChange",
"offNetworkStatusChange",
"offWindowResize",
"onAccelerometerChange",
"onCompassChange",
"onGyroscopeChange",
"onMemoryWarning",
"onNetworkStatusChange",
"onSocketClose",
"onSocketError",
"onSocketMessage",
"onSocketOpen",
"onTabBarMidButtonTap",
"onUserCaptureScreen",
"onWindowResize",
"openDocument",
"openLocation",
"pageScrollTo",
"preloadPage",
"previewImage",
"promiseInterceptor",
"reLaunch",
"redirectTo",
"removeInterceptor",
"removeSavedFileInfo",
"removeStorage",
"removeStorageSync",
"removeTabBarBadge",
"request",
"saveFile",
"saveImageToPhotosAlbum",
"saveVideoToPhotosAlbum",
"scanCode",
"sendSocketMessage",
"setKeepScreenOn",
"setLeftWindowStyle",
"setNavigationBarColor",
"setNavigationBarTitle",
"setRightWindowStyle",
"setScreenBrightness",
"setStorage",
"setStorageSync",
"setTabBarBadge",
"setTabBarItem",
"setTabBarStyle",
"setTopWindowStyle",
"showActionSheet",
"showLeftWindow",
"showLoading",
"showModal",
"showNavigationBarLoading",
"showRightWindow",
"showTabBar",
"showTabBarRedDot",
"showToast",
"showTopWindow",
"startAccelerometer",
"startCompass",
"startGyroscope",
"startPullDownRefresh",
"stopAccelerometer",
"stopCompass",
"stopGyroscope",
"stopPullDownRefresh",
"switchTab",
"uploadFile",
"upx2px",
"vibrateLong",
"vibrateShort"
]
\ No newline at end of file
import path from 'path'
import { Plugin, ResolvedConfig } from 'vite'
import { extend } from '@vue/shared'
......@@ -11,9 +12,13 @@ import {
isCombineBuiltInCss,
} from '@dcloudio/uni-cli-shared'
const apiJson = require(path.resolve(__dirname, '../../lib/api.json'))
const uniInjectPluginOptions: Partial<InjectOptions> = {
exclude: [...COMMON_EXCLUDE],
'uni.': '@dcloudio/uni-h5',
'uni.': [
'@dcloudio/uni-h5',
((method: string) => apiJson.includes(method)) as any, // API白名单
],
getApp: ['@dcloudio/uni-h5', 'getApp'],
getCurrentPages: ['@dcloudio/uni-h5', 'getCurrentPages'],
UniServiceJSBridge: ['@dcloudio/uni-h5', 'UniServiceJSBridge'],
......
......@@ -24,10 +24,8 @@ export function uniPagesJsonPlugin(): Plugin {
const { resolvedConfig } = opts
return {
code:
(resolvedConfig.command === 'serve' ||
(resolvedConfig.command === 'build' && ssr)
? registerGlobalCode(resolvedConfig, ssr)
: '') + generatePagesJsonCode(ssr, code, resolvedConfig),
registerGlobalCode(resolvedConfig, ssr) +
generatePagesJsonCode(ssr, code, resolvedConfig),
map: { mappings: '' },
}
}
......@@ -81,6 +79,11 @@ function getGlobal(ssr?: boolean) {
function registerGlobalCode(config: ResolvedConfig, ssr?: boolean) {
const name = getGlobal(ssr)
if (config.command === 'build' && !ssr) {
// 非SSR的发行模式,补充全局 uni 对象
return `${name}.uni = {}`
}
const rpx2pxCode =
!ssr && config.define!.__UNI_FEATURE_RPX__
? `import {upx2px} from '@dcloudio/uni-h5'
......
此差异已折叠。
......@@ -12,6 +12,7 @@ import { OutputChunk } from 'rollup'
import { stripOptions } from '@dcloudio/uni-cli-shared'
import { isCustomElement } from '@dcloudio/uni-shared'
import { genApiJson } from './api'
function resolve(file: string) {
return path.resolve(__dirname, file)
......@@ -55,6 +56,7 @@ if (FORMAT === 'es') {
'__IMPORT_META_ENV_BASE_URL__',
'import.meta.env.BASE_URL'
)
genApiJson(esBundle.code)
}
},
})
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册