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

feat(h5): build treeshaking for api

上级 b74ce0ad
......@@ -19,11 +19,8 @@ type API_TYPES =
| typeof API_TYPE_SYNC
| typeof API_TYPE_ASYNC
function validateProtocol(
_name: string,
_args: any[],
_protocol: ApiProtocols
) {
function validateProtocol(name: string, args: any[], protocol: ApiProtocols) {
console.log('validateProtocol', name, args, protocol)
return true
}
......@@ -71,10 +68,16 @@ function wrapperApi<T extends Function>(
export function createOnApi<T extends Function>(
name: string,
fn: T,
options?: ApiOptions,
protocol?: ApiProtocols
protocol?: ApiProtocols,
options?: ApiOptions
) {
return createApi(API_TYPE_ON, name, fn, protocol, options)
return createApi(
API_TYPE_ON,
name,
fn,
__DEV__ ? protocol : undefined,
options
)
}
export function createTaskApi<T extends Function>(
......@@ -83,7 +86,13 @@ export function createTaskApi<T extends Function>(
protocol?: ApiProtocols,
options?: ApiOptions
) {
return createApi(API_TYPE_TASK, name, fn, protocol, options)
return createApi(
API_TYPE_TASK,
name,
fn,
__DEV__ ? protocol : undefined,
options
)
}
export function createSyncApi<T extends Function>(
......@@ -92,7 +101,13 @@ export function createSyncApi<T extends Function>(
protocol?: ApiProtocols,
options?: ApiOptions
) {
return createApi(API_TYPE_SYNC, name, fn, protocol, options)
return createApi(
API_TYPE_SYNC,
name,
fn,
__DEV__ ? protocol : undefined,
options
)
}
export function createAsyncApi<T extends Function>(
......@@ -101,7 +116,9 @@ export function createAsyncApi<T extends Function>(
protocol?: ApiProtocols,
options?: ApiOptions
) {
return promisify(createApi(API_TYPE_ASYNC, name, fn, protocol, options))
return promisify(
createApi(API_TYPE_ASYNC, name, fn, __DEV__ ? protocol : undefined, options)
)
}
function createApi<T extends Function>(
......
import { plugin } from '@dcloudio/uni-h5';
import { isSymbol, extend, isMap, isObject, toRawType, def, isArray, isString, isFunction, isPromise, toHandlerKey, remove, EMPTY_OBJ, camelize, capitalize, EMPTY_ARR, normalizeClass, normalizeStyle, isOn, NOOP, isGloballyWhitelisted, toNumber, invokeArrayFns, looseIndexOf, isSet, looseEqual, hyphenate, isHTMLTag, isSVGTag, isIntegerKey, hasOwn, hasChanged, getGlobalThis, isReservedProp, NO, isModelListener, makeMap, isSpecialBooleanAttr } from '@vue/shared';
export { camelize, capitalize, toDisplayString, toHandlerKey } from '@vue/shared';
......@@ -9122,9 +9121,4 @@ const onNavigationBarSearchInputClicked = /*#__PURE__*/ createHook$1("onNavigati
const onNavigationBarSearchInputConfirmed = /*#__PURE__*/ createHook$1("onNavigationBarSearchInputConfirmed" /* ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED */);
const onNavigationBarSearchInputFocusChanged = /*#__PURE__*/ createHook$1("onNavigationBarSearchInputFocusChanged" /* ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED */);
function createApp(rootComponent, rootProps = null) {
rootComponent && (rootComponent.mpType = 'app');
return createVueApp(rootComponent, rootProps).use(plugin);
}
export { BaseTransition, Comment, Fragment, KeepAlive, Static, Suspense, Teleport, Text, Transition, TransitionGroup, callWithAsyncErrorHandling, callWithErrorHandling, cloneVNode, compile$1 as compile, computed$1 as computed, createApp, createBlock, createCommentVNode, createHook$1 as createHook, createHydrationRenderer, createRenderer, createSSRApp, createSlots, createStaticVNode, createTextVNode, createVNode, createVueApp, customRef, defineAsyncComponent, defineComponent, defineEmit, defineProps, devtools, getCurrentInstance, getTransitionRawChildren, h, handleError, hydrate, initCustomFormatter, inject, injectHook, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, isVNode, markRaw, mergeProps, nextTick, onActivated, onAddToFavorites, onBackPress, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onError, onErrorCaptured, onHide, onLaunch, onLoad, onMounted, onNavigationBarButtonTap, onNavigationBarSearchInputChanged, onNavigationBarSearchInputClicked, onNavigationBarSearchInputConfirmed, onNavigationBarSearchInputFocusChanged, onPageNotFound, onPageScroll, onPullDownRefresh, onReachBottom, onReady, onRenderTracked, onRenderTriggered, onResize, onShareAppMessage, onShareTimeline, onShow, onTabItemTap, onThemeChange, onUnhandledRejection, onUnload, onUnmounted, onUpdated, openBlock, popScopeId, provide, proxyRefs, pushScopeId, queuePostFlushCb, reactive, readonly, ref, registerRuntimeCompiler, render, renderList, renderSlot, resolveComponent, resolveDirective, resolveDynamicComponent, resolveTransitionHooks, setBlockTracking, setDevtoolsHook, setTransitionHooks, shallowReactive, shallowReadonly, shallowRef, ssrContextKey, ssrUtils, toHandlers, toRaw, toRef, toRefs, transformVNodeArgs, triggerRef, unref, useContext, useCssModule, useCssVars, useSSRContext, useTransitionState, vModelCheckbox, vModelDynamic, vModelRadio, vModelSelect, vModelText, vShow, version, warn, watch, watchEffect, withCtx, withDirectives, withKeys, withModifiers, withScopeId };
export { BaseTransition, Comment, Fragment, KeepAlive, Static, Suspense, Teleport, Text, Transition, TransitionGroup, callWithAsyncErrorHandling, callWithErrorHandling, cloneVNode, compile$1 as compile, computed$1 as computed, createBlock, createCommentVNode, createHook$1 as createHook, createHydrationRenderer, createRenderer, createSSRApp, createSlots, createStaticVNode, createTextVNode, createVNode, createVueApp, customRef, defineAsyncComponent, defineComponent, defineEmit, defineProps, devtools, getCurrentInstance, getTransitionRawChildren, h, handleError, hydrate, initCustomFormatter, inject, injectHook, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, isVNode, markRaw, mergeProps, nextTick, onActivated, onAddToFavorites, onBackPress, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onError, onErrorCaptured, onHide, onLaunch, onLoad, onMounted, onNavigationBarButtonTap, onNavigationBarSearchInputChanged, onNavigationBarSearchInputClicked, onNavigationBarSearchInputConfirmed, onNavigationBarSearchInputFocusChanged, onPageNotFound, onPageScroll, onPullDownRefresh, onReachBottom, onReady, onRenderTracked, onRenderTriggered, onResize, onShareAppMessage, onShareTimeline, onShow, onTabItemTap, onThemeChange, onUnhandledRejection, onUnload, onUnmounted, onUpdated, openBlock, popScopeId, provide, proxyRefs, pushScopeId, queuePostFlushCb, reactive, readonly, ref, registerRuntimeCompiler, render, renderList, renderSlot, resolveComponent, resolveDirective, resolveDynamicComponent, resolveTransitionHooks, setBlockTracking, setDevtoolsHook, setTransitionHooks, shallowReactive, shallowReadonly, shallowRef, ssrContextKey, ssrUtils, toHandlers, toRaw, toRef, toRefs, transformVNodeArgs, triggerRef, unref, useContext, useCssModule, useCssVars, useSSRContext, useTransitionState, vModelCheckbox, vModelDynamic, vModelRadio, vModelSelect, vModelText, vShow, version, warn, watch, watchEffect, withCtx, withDirectives, withKeys, withModifiers, withScopeId };
import { plugin } from '@dcloudio/uni-h5'
// @ts-ignore
import { createVueApp } from '../lib/vue.runtime.esm.js'
export function createApp(rootComponent: unknown, rootProps = null) {
rootComponent && ((rootComponent as any).mpType = 'app')
return createVueApp(rootComponent, rootProps).use(plugin)
}
// @ts-ignore
export * from '../lib/vue.runtime.esm.js'
export * from '@dcloudio/uni-vue/src/apiLifecycle'
......@@ -1407,7 +1407,8 @@ const API_TYPE_ON = 0;
const API_TYPE_TASK = 1;
const API_TYPE_SYNC = 2;
const API_TYPE_ASYNC = 3;
function validateProtocol(_name, _args, _protocol) {
function validateProtocol(name, args, protocol) {
console.log("validateProtocol", name, args, protocol);
return true;
}
function formatApiArgs(args, options) {
......@@ -1433,16 +1434,16 @@ function wrapperAsyncApi(name, fn, options) {
}
function wrapperApi(fn, name, protocol, options) {
return function(...args) {
if (!(process.env.NODE_ENV !== "production" && protocol && !validateProtocol())) {
if (!(process.env.NODE_ENV !== "production" && protocol && !validateProtocol(name, args, protocol))) {
return fn.apply(null, formatApiArgs(args));
}
};
}
function createSyncApi(name, fn, protocol, options) {
return createApi(API_TYPE_SYNC, name, fn, protocol, options);
return createApi(API_TYPE_SYNC, name, fn, process.env.NODE_ENV !== "production" ? protocol : void 0, options);
}
function createAsyncApi(name, fn, protocol, options) {
return promisify(createApi(API_TYPE_ASYNC, name, fn, protocol, options));
return promisify(createApi(API_TYPE_ASYNC, name, fn, process.env.NODE_ENV !== "production" ? protocol : void 0, options));
}
function createApi(type, name, fn, protocol, options) {
switch (type) {
......
......@@ -113,7 +113,8 @@ const API_TYPE_ON = 0;
const API_TYPE_TASK = 1;
const API_TYPE_SYNC = 2;
const API_TYPE_ASYNC = 3;
function validateProtocol(_name, _args, _protocol) {
function validateProtocol(name, args, protocol) {
console.log('validateProtocol', name, args, protocol);
return true;
}
function formatApiArgs(args, options) {
......@@ -139,13 +140,13 @@ function wrapperAsyncApi(name, fn, options) {
}
function wrapperApi(fn, name, protocol, options) {
return function (...args) {
if (!((process.env.NODE_ENV !== 'production') && protocol && !validateProtocol())) {
if (!((process.env.NODE_ENV !== 'production') && protocol && !validateProtocol(name, args, protocol))) {
return fn.apply(null, formatApiArgs(args));
}
};
}
function createSyncApi(name, fn, protocol, options) {
return createApi(API_TYPE_SYNC, name, fn, protocol, options);
return createApi(API_TYPE_SYNC, name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options);
}
function createApi(type, name, fn, protocol, options) {
switch (type) {
......
......@@ -113,7 +113,8 @@ const API_TYPE_ON = 0;
const API_TYPE_TASK = 1;
const API_TYPE_SYNC = 2;
const API_TYPE_ASYNC = 3;
function validateProtocol(_name, _args, _protocol) {
function validateProtocol(name, args, protocol) {
console.log('validateProtocol', name, args, protocol);
return true;
}
function formatApiArgs(args, options) {
......@@ -139,13 +140,13 @@ function wrapperAsyncApi(name, fn, options) {
}
function wrapperApi(fn, name, protocol, options) {
return function (...args) {
if (!((process.env.NODE_ENV !== 'production') && protocol && !validateProtocol())) {
if (!((process.env.NODE_ENV !== 'production') && protocol && !validateProtocol(name, args, protocol))) {
return fn.apply(null, formatApiArgs(args));
}
};
}
function createSyncApi(name, fn, protocol, options) {
return createApi(API_TYPE_SYNC, name, fn, protocol, options);
return createApi(API_TYPE_SYNC, name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options);
}
function createApi(type, name, fn, protocol, options) {
switch (type) {
......
......@@ -113,7 +113,8 @@ const API_TYPE_ON = 0;
const API_TYPE_TASK = 1;
const API_TYPE_SYNC = 2;
const API_TYPE_ASYNC = 3;
function validateProtocol(_name, _args, _protocol) {
function validateProtocol(name, args, protocol) {
console.log('validateProtocol', name, args, protocol);
return true;
}
function formatApiArgs(args, options) {
......@@ -139,13 +140,13 @@ function wrapperAsyncApi(name, fn, options) {
}
function wrapperApi(fn, name, protocol, options) {
return function (...args) {
if (!((process.env.NODE_ENV !== 'production') && protocol && !validateProtocol())) {
if (!((process.env.NODE_ENV !== 'production') && protocol && !validateProtocol(name, args, protocol))) {
return fn.apply(null, formatApiArgs(args));
}
};
}
function createSyncApi(name, fn, protocol, options) {
return createApi(API_TYPE_SYNC, name, fn, protocol, options);
return createApi(API_TYPE_SYNC, name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options);
}
function createApi(type, name, fn, protocol, options) {
switch (type) {
......
......@@ -113,7 +113,8 @@ const API_TYPE_ON = 0;
const API_TYPE_TASK = 1;
const API_TYPE_SYNC = 2;
const API_TYPE_ASYNC = 3;
function validateProtocol(_name, _args, _protocol) {
function validateProtocol(name, args, protocol) {
console.log('validateProtocol', name, args, protocol);
return true;
}
function formatApiArgs(args, options) {
......@@ -139,13 +140,13 @@ function wrapperAsyncApi(name, fn, options) {
}
function wrapperApi(fn, name, protocol, options) {
return function (...args) {
if (!((process.env.NODE_ENV !== 'production') && protocol && !validateProtocol())) {
if (!((process.env.NODE_ENV !== 'production') && protocol && !validateProtocol(name, args, protocol))) {
return fn.apply(null, formatApiArgs(args));
}
};
}
function createSyncApi(name, fn, protocol, options) {
return createApi(API_TYPE_SYNC, name, fn, protocol, options);
return createApi(API_TYPE_SYNC, name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options);
}
function createApi(type, name, fn, protocol, options) {
switch (type) {
......
......@@ -113,7 +113,8 @@ const API_TYPE_ON = 0;
const API_TYPE_TASK = 1;
const API_TYPE_SYNC = 2;
const API_TYPE_ASYNC = 3;
function validateProtocol(_name, _args, _protocol) {
function validateProtocol(name, args, protocol) {
console.log('validateProtocol', name, args, protocol);
return true;
}
function formatApiArgs(args, options) {
......@@ -139,13 +140,13 @@ function wrapperAsyncApi(name, fn, options) {
}
function wrapperApi(fn, name, protocol, options) {
return function (...args) {
if (!((process.env.NODE_ENV !== 'production') && protocol && !validateProtocol())) {
if (!((process.env.NODE_ENV !== 'production') && protocol && !validateProtocol(name, args, protocol))) {
return fn.apply(null, formatApiArgs(args));
}
};
}
function createSyncApi(name, fn, protocol, options) {
return createApi(API_TYPE_SYNC, name, fn, protocol, options);
return createApi(API_TYPE_SYNC, name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options);
}
function createApi(type, name, fn, protocol, options) {
switch (type) {
......
......@@ -113,7 +113,8 @@ const API_TYPE_ON = 0;
const API_TYPE_TASK = 1;
const API_TYPE_SYNC = 2;
const API_TYPE_ASYNC = 3;
function validateProtocol(_name, _args, _protocol) {
function validateProtocol(name, args, protocol) {
console.log('validateProtocol', name, args, protocol);
return true;
}
function formatApiArgs(args, options) {
......@@ -139,13 +140,13 @@ function wrapperAsyncApi(name, fn, options) {
}
function wrapperApi(fn, name, protocol, options) {
return function (...args) {
if (!((process.env.NODE_ENV !== 'production') && protocol && !validateProtocol())) {
if (!((process.env.NODE_ENV !== 'production') && protocol && !validateProtocol(name, args, protocol))) {
return fn.apply(null, formatApiArgs(args));
}
};
}
function createSyncApi(name, fn, protocol, options) {
return createApi(API_TYPE_SYNC, name, fn, protocol, options);
return createApi(API_TYPE_SYNC, name, fn, (process.env.NODE_ENV !== 'production') ? protocol : undefined, options);
}
function createApi(type, name, fn, protocol, options) {
switch (type) {
......
......@@ -19,8 +19,9 @@ export const main = {
if (!pagesJsPath) {
pagesJsPath = slash(path.resolve(options.inputDir, 'pages.json.js'))
}
return `import '${pagesJsPath}';${fs
return `import { plugin } from '@dcloudio/uni-h5';import '${pagesJsPath}';function createApp(rootComponent,rootProps){rootComponent && (rootComponent.mpType = 'app');return createVueApp(rootComponent, rootProps).use(plugin)};${fs
.readFileSync(filename, 'utf-8')
.toString()}`
.toString()
.replace('createApp', 'createVueApp')}`
},
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册