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

fix(h5): hot reload

上级 80e5bb3f
......@@ -21,5 +21,6 @@ declare namespace NodeJS {
UNI_APP_CODE_SPLITING?: 'true'
UNI_AUTOMATOR_WS_ENDPOINT?: string
UNI_H5_BASE?: string
UNI_H5_BROWSER?: 'builtin'
}
}
import path from 'path'
import {
initAppProvide,
uniViteInjectPlugin,
uniCssScopedPlugin,
getAppStyleIsolation,
parseManifestJsonOnce,
uniConsolePlugin,
uniHBuilderXConsolePlugin,
UNI_EASYCOM_EXCLUDE,
isVueSfcFile,
isUniPageFile,
......@@ -43,15 +42,7 @@ function initUniCssScopedPluginFilter(
const plugins = [
uniEasycomPlugin({ exclude: UNI_EASYCOM_EXCLUDE }),
// uniResolveIdPlugin(),
uniConsolePlugin({
filename(filename) {
filename = path.relative(process.env.UNI_INPUT_DIR, filename)
if (filename.startsWith('.') || path.isAbsolute(filename)) {
return ''
}
return filename
},
}),
uniHBuilderXConsolePlugin(),
uniMainJsPlugin(),
uniManifestJsonPlugin(),
uniPagesJsonPlugin(),
......
export { initDefine } from './define'
export { initAppProvide } from './provide'
export { initAppProvide, initH5Provide } from './provide'
import path from 'path'
const libDir = path.resolve(__dirname, '../../lib')
export function initAppProvide() {
const cryptoDefine = [path.join(libDir, 'crypto.js'), 'default']
return {
......@@ -9,3 +11,9 @@ export function initAppProvide() {
'global.crypto': cryptoDefine,
}
}
export function initH5Provide() {
return {
__f__: ['@dcloudio/uni-shared', 'formatH5Log'],
}
}
import path from 'path'
import { normalizePath } from '../utils'
import { uniConsolePlugin } from '../vite/plugins/console'
export * from './env'
export {
initModuleAlias,
installHBuilderXPlugin,
formatInstallHBuilderXPluginTips,
} from './alias'
export function uniHBuilderXConsolePlugin() {
return uniConsolePlugin({
filename(filename) {
filename = path.relative(process.env.UNI_INPUT_DIR, filename)
if (filename.startsWith('.') || path.isAbsolute(filename)) {
return ''
}
return normalizePath(filename)
},
})
}
......@@ -16,9 +16,8 @@ const debugConsole = debug('vite:uni:console')
export function uniConsolePlugin(options: ConsoleOptions): Plugin {
const filter = createFilter(options.include, options.exclude)
return {
name: 'vite:uni-app-console',
name: 'vite:uni-console',
enforce: 'pre',
apply: 'build',
transform(code, id) {
if (!filter(id)) return null
if (!isJsFile(id)) return null
......
import {
initH5Provide,
isVueSfcFile,
uniCssScopedPlugin,
uniHBuilderXConsolePlugin,
uniViteInjectPlugin,
UNI_EASYCOM_EXCLUDE,
} from '@dcloudio/uni-cli-shared'
import { uniH5PLugin } from './plugin'
......@@ -21,6 +24,9 @@ export default [
filter: (id) => isVueSfcFile(id) && !id.endsWith('App.vue'),
}),
uniResolveIdPlugin(),
...(process.env.UNI_H5_BROWSER === 'builtin'
? [uniViteInjectPlugin(initH5Provide()), uniHBuilderXConsolePlugin()]
: []),
uniMainJsPlugin(),
uniManifestJsonPlugin(),
uniPagesJsonPlugin(),
......
......@@ -105,6 +105,7 @@ ${name}.wx = uni
${name}.uni = uni
${name}.UniViewJSBridge = UniViewJSBridge
${name}.UniServiceJSBridge = UniServiceJSBridge
${name}.__setupPage = setupPage
`
}
......
......@@ -1172,6 +1172,12 @@ function reload(id, newComp) {
const record = map.get(id);
if (!record)
return;
// fixed by xxxxxx 解决页面刷新 setupPage
if (typeof window !== 'undefined' &&
window.__setupPage &&
record.initialDef.__mpType === 'page') {
window.__setupPage(newComp);
}
newComp = normalizeClassComponent(newComp);
// update initial def (for not-yet-rendered components)
updateComponentDef(record.initialDef, newComp);
......
......@@ -1185,6 +1185,12 @@ function reload(id, newComp) {
const record = map.get(id);
if (!record)
return;
// fixed by xxxxxx 解决页面刷新 setupPage
if (typeof window !== 'undefined' &&
window.__setupPage &&
record.initialDef.__mpType === 'page') {
window.__setupPage(newComp);
}
newComp = normalizeClassComponent(newComp);
// update initial def (for not-yet-rendered components)
updateComponentDef(record.initialDef, newComp);
......
......@@ -2918,6 +2918,10 @@ const props$o = /* @__PURE__ */ shared.extend({}, {
confirmType: {
type: String,
default: "done"
},
confirmHold: {
type: Boolean,
default: false
}
}, props$r);
const emit = [
......@@ -3197,10 +3201,12 @@ var Input = /* @__PURE__ */ defineBuiltInComponent({
if (event.key !== "Enter") {
return;
}
const input = event.target;
event.stopPropagation();
trigger("confirm", event, {
value: event.target.value
value: input.value
});
!props2.confirmHold && input.blur();
}
return () => {
let inputNode = props2.disabled && fixDisabledColor ? vue.createVNode("input", {
......@@ -6438,7 +6444,7 @@ var index$i = /* @__PURE__ */ defineBuiltInComponent({
if (isDone.value) {
confirm(event);
const textarea = event.target;
textarea.blur();
!props2.confirmHold && textarea.blur();
}
}
return () => {
......@@ -6935,6 +6941,9 @@ function setupWindow(comp, id) {
});
}
function setupPage(comp) {
if (process.env.NODE_ENV !== "production") {
comp.__mpType = "page";
}
return setupComponent(comp, {
init: initPage,
setup(instance) {
......@@ -6948,6 +6957,9 @@ function setupPage(comp) {
});
}
function setupApp(comp) {
if (process.env.NODE_ENV !== "production") {
comp.__mpType = "app";
}
return setupComponent(comp, {
init: initApp,
setup(instance) {
......
......@@ -8308,6 +8308,10 @@ const props$v = /* @__PURE__ */ extend({}, {
confirmType: {
type: String,
default: "done"
},
confirmHold: {
type: Boolean,
default: false
}
}, props$y);
const emit = [
......@@ -8596,10 +8600,12 @@ var Input = /* @__PURE__ */ defineBuiltInComponent({
if (event.key !== "Enter") {
return;
}
const input = event.target;
event.stopPropagation();
trigger("confirm", event, {
value: event.target.value
value: input.value
});
!props2.confirmHold && input.blur();
}
return () => {
let inputNode = props2.disabled && fixDisabledColor ? createVNode("input", {
......@@ -13268,7 +13274,7 @@ var index$i = /* @__PURE__ */ defineBuiltInComponent({
if (isDone.value) {
confirm(event);
const textarea = event.target;
textarea.blur();
!props2.confirmHold && textarea.blur();
}
}
{
......@@ -13989,6 +13995,9 @@ function setupWindow(comp, id2) {
});
}
function setupPage(comp) {
if (process.env.NODE_ENV !== "production") {
comp.__mpType = "page";
}
return setupComponent(comp, {
init: initPage,
setup(instance2) {
......@@ -14028,6 +14037,9 @@ function setupPage(comp) {
});
}
function setupApp(comp) {
if (process.env.NODE_ENV !== "production") {
comp.__mpType = "app";
}
return setupComponent(comp, {
init: initApp,
setup(instance2) {
......
......@@ -75,6 +75,9 @@ export function setupWindow(comp: any, id: number) {
}
export function setupPage(comp: any) {
if (__DEV__) {
comp.__mpType = 'page'
}
return setupComponent(comp, {
init: initPage,
setup(instance) {
......@@ -121,6 +124,9 @@ export function setupPage(comp: any) {
}
export function setupApp(comp: any) {
if (__DEV__) {
comp.__mpType = 'app'
}
return setupComponent(comp, {
init: initApp,
setup(instance) {
......
......@@ -482,6 +482,9 @@ function normalizeLog(type, filename, args) {
function formatAppLog(type, filename, ...args) {
const res = normalizeLog(type, filename, args);
res && console[type](res);
}
function formatH5Log(type, filename, ...args) {
console[type].apply(console, [...args, filename]);
}
let latestNodeId = 1;
......@@ -1309,6 +1312,7 @@ exports.dynamicSlotName = dynamicSlotName;
exports.forcePatchProp = forcePatchProp;
exports.formatAppLog = formatAppLog;
exports.formatDateTime = formatDateTime;
exports.formatH5Log = formatH5Log;
exports.formatLog = formatLog;
exports.getCustomDataset = getCustomDataset;
exports.getEnvLocale = getEnvLocale;
......
......@@ -189,6 +189,8 @@ export declare function formatDateTime({ date, mode }: {
mode?: string | undefined;
}): string;
export declare function formatH5Log(type: keyof Console, filename: string, ...args: unknown[]): void;
export declare function formatLog(module: string, ...args: any[]): string;
export declare function getCustomDataset(el: HTMLElement | HTMLElementWithDataset): DOMStringMap & Record<string, any>;
......
......@@ -478,6 +478,9 @@ function normalizeLog(type, filename, args) {
function formatAppLog(type, filename, ...args) {
const res = normalizeLog(type, filename, args);
res && console[type](res);
}
function formatH5Log(type, filename, ...args) {
console[type].apply(console, [...args, filename]);
}
let latestNodeId = 1;
......@@ -1193,4 +1196,4 @@ function getEnvLocale() {
return (lang && lang.replace(/[.:].*/, '')) || 'en';
}
export { ACTION_TYPE_ADD_EVENT, ACTION_TYPE_ADD_WXS_EVENT, ACTION_TYPE_CREATE, ACTION_TYPE_EVENT, ACTION_TYPE_INSERT, ACTION_TYPE_PAGE_CREATE, ACTION_TYPE_PAGE_CREATED, ACTION_TYPE_PAGE_SCROLL, ACTION_TYPE_REMOVE, ACTION_TYPE_REMOVE_ATTRIBUTE, ACTION_TYPE_REMOVE_EVENT, ACTION_TYPE_SET_ATTRIBUTE, ACTION_TYPE_SET_TEXT, ATTR_CHANGE_PREFIX, ATTR_CLASS, ATTR_INNER_HTML, ATTR_STYLE, ATTR_TEXT_CONTENT, ATTR_V_OWNER_ID, ATTR_V_RENDERJS, ATTR_V_SHOW, BACKGROUND_COLOR, BUILT_IN_TAGS, COMPONENT_NAME_PREFIX, COMPONENT_PREFIX, COMPONENT_SELECTOR_PREFIX, DATA_RE, EventChannel, EventModifierFlags, I18N_JSON_DELIMITERS, JSON_PROTOCOL, LINEFEED, NAVBAR_HEIGHT, NODE_TYPE_COMMENT, NODE_TYPE_ELEMENT, NODE_TYPE_PAGE, NODE_TYPE_TEXT, NVueTextNode, ON_ADD_TO_FAVORITES, ON_APP_ENTER_BACKGROUND, ON_APP_ENTER_FOREGROUND, ON_BACK_PRESS, ON_ERROR, ON_HIDE, ON_KEYBOARD_HEIGHT_CHANGE, ON_LAUNCH, ON_LOAD, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ON_PAGE_NOT_FOUND, ON_PAGE_SCROLL, ON_PULL_DOWN_REFRESH, ON_REACH_BOTTOM, ON_REACH_BOTTOM_DISTANCE, ON_READY, ON_RESIZE, ON_SHARE_APP_MESSAGE, ON_SHARE_TIMELINE, ON_SHOW, ON_TAB_ITEM_TAP, ON_THEME_CHANGE, ON_UNHANDLE_REJECTION, ON_UNLOAD, ON_WEB_INVOKE_APP_SERVICE, ON_WXS_INVOKE_CALL_METHOD, PLUS_RE, PRIMARY_COLOR, RENDERJS_MODULES, RESPONSIVE_MIN_WIDTH, SCHEME_RE, SELECTED_COLOR, SLOT_DEFAULT_NAME, TABBAR_HEIGHT, TAGS, UNI_SSR, UNI_SSR_DATA, UNI_SSR_GLOBAL_DATA, UNI_SSR_STORE, UNI_SSR_TITLE, UNI_STORAGE_LOCALE, UniBaseNode, UniCommentNode, UniElement, UniEvent, UniInputElement, UniLifecycleHooks, UniNode, UniTextAreaElement, UniTextNode, WEB_INVOKE_APPSERVICE, WXS_MODULES, WXS_PROTOCOL, addFont, addLeadingSlash, cache, cacheStringFunction, callOptions, createIsCustomElement, createRpx2Unit, createUniEvent, debounce, decode, decodedQuery, defaultMiniProgramRpx2Unit, defaultRpx2Unit, dynamicSlotName, forcePatchProp, formatAppLog, formatDateTime, formatLog, getCustomDataset, getEnvLocale, getLen, getValueByDataPath, initCustomDataset, invokeArrayFns, isAppNativeTag, isBuiltInComponent, isComponentTag, isH5CustomElement, isH5NativeTag, isMiniProgramNativeTag, isRootHook, normalizeDataset, normalizeEventType, normalizeTarget, once, parseEventName, parseQuery, parseUrl, passive, plusReady, removeLeadingSlash, resolveOwnerEl, resolveOwnerVm, sanitise, scrollTo, stringifyQuery, updateElementStyle };
export { ACTION_TYPE_ADD_EVENT, ACTION_TYPE_ADD_WXS_EVENT, ACTION_TYPE_CREATE, ACTION_TYPE_EVENT, ACTION_TYPE_INSERT, ACTION_TYPE_PAGE_CREATE, ACTION_TYPE_PAGE_CREATED, ACTION_TYPE_PAGE_SCROLL, ACTION_TYPE_REMOVE, ACTION_TYPE_REMOVE_ATTRIBUTE, ACTION_TYPE_REMOVE_EVENT, ACTION_TYPE_SET_ATTRIBUTE, ACTION_TYPE_SET_TEXT, ATTR_CHANGE_PREFIX, ATTR_CLASS, ATTR_INNER_HTML, ATTR_STYLE, ATTR_TEXT_CONTENT, ATTR_V_OWNER_ID, ATTR_V_RENDERJS, ATTR_V_SHOW, BACKGROUND_COLOR, BUILT_IN_TAGS, COMPONENT_NAME_PREFIX, COMPONENT_PREFIX, COMPONENT_SELECTOR_PREFIX, DATA_RE, EventChannel, EventModifierFlags, I18N_JSON_DELIMITERS, JSON_PROTOCOL, LINEFEED, NAVBAR_HEIGHT, NODE_TYPE_COMMENT, NODE_TYPE_ELEMENT, NODE_TYPE_PAGE, NODE_TYPE_TEXT, NVueTextNode, ON_ADD_TO_FAVORITES, ON_APP_ENTER_BACKGROUND, ON_APP_ENTER_FOREGROUND, ON_BACK_PRESS, ON_ERROR, ON_HIDE, ON_KEYBOARD_HEIGHT_CHANGE, ON_LAUNCH, ON_LOAD, ON_NAVIGATION_BAR_BUTTON_TAP, ON_NAVIGATION_BAR_SEARCH_INPUT_CHANGED, ON_NAVIGATION_BAR_SEARCH_INPUT_CLICKED, ON_NAVIGATION_BAR_SEARCH_INPUT_CONFIRMED, ON_NAVIGATION_BAR_SEARCH_INPUT_FOCUS_CHANGED, ON_PAGE_NOT_FOUND, ON_PAGE_SCROLL, ON_PULL_DOWN_REFRESH, ON_REACH_BOTTOM, ON_REACH_BOTTOM_DISTANCE, ON_READY, ON_RESIZE, ON_SHARE_APP_MESSAGE, ON_SHARE_TIMELINE, ON_SHOW, ON_TAB_ITEM_TAP, ON_THEME_CHANGE, ON_UNHANDLE_REJECTION, ON_UNLOAD, ON_WEB_INVOKE_APP_SERVICE, ON_WXS_INVOKE_CALL_METHOD, PLUS_RE, PRIMARY_COLOR, RENDERJS_MODULES, RESPONSIVE_MIN_WIDTH, SCHEME_RE, SELECTED_COLOR, SLOT_DEFAULT_NAME, TABBAR_HEIGHT, TAGS, UNI_SSR, UNI_SSR_DATA, UNI_SSR_GLOBAL_DATA, UNI_SSR_STORE, UNI_SSR_TITLE, UNI_STORAGE_LOCALE, UniBaseNode, UniCommentNode, UniElement, UniEvent, UniInputElement, UniLifecycleHooks, UniNode, UniTextAreaElement, UniTextNode, WEB_INVOKE_APPSERVICE, WXS_MODULES, WXS_PROTOCOL, addFont, addLeadingSlash, cache, cacheStringFunction, callOptions, createIsCustomElement, createRpx2Unit, createUniEvent, debounce, decode, decodedQuery, defaultMiniProgramRpx2Unit, defaultRpx2Unit, dynamicSlotName, forcePatchProp, formatAppLog, formatDateTime, formatH5Log, formatLog, getCustomDataset, getEnvLocale, getLen, getValueByDataPath, initCustomDataset, invokeArrayFns, isAppNativeTag, isBuiltInComponent, isComponentTag, isH5CustomElement, isH5NativeTag, isMiniProgramNativeTag, isRootHook, normalizeDataset, normalizeEventType, normalizeTarget, once, parseEventName, parseQuery, parseUrl, passive, plusReady, removeLeadingSlash, resolveOwnerEl, resolveOwnerVm, sanitise, scrollTo, stringifyQuery, updateElementStyle };
......@@ -62,3 +62,11 @@ export function formatAppLog(
const res = normalizeLog(type, filename, args)
res && console[type](res)
}
export function formatH5Log(
type: keyof Console,
filename: string,
...args: unknown[]
) {
;(console[type] as Function).apply(console, [...args, filename])
}
export { formatAppLog } from './formatLog'
export { formatAppLog, formatH5Log } from './formatLog'
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册