# VConsole 工具

运行时工具。可用于初始化 VConsole

# 如何使用

安装

pnpm add vconsole-helper -D

main.ts 中:

import { loadVConsole } from 'vconsole-helper';

loadVConsole();


// options 会传递给 new window.VConsole
// plugins 会通过下面方式注册 vConsole.addPlugin(plugin())
loadVConsole(options, plugins);

由于 vconsole 本身是调试工具,无需放到首包中,所以性能更佳的使用方法是使用外链:

const VCONSOLE_HELPER_SCRIPT = 'https://image-1251917893.file.myqcloud.com/igame/npm/vconsole-helper/index%400.0.4.prod.js';

function innerLoadVConsole() {
  if (!window.vConsoleHelper) return;

  const { genVConsole, V_CONSOLE_NO_DELAY = {} } = window.vConsoleHelper;
  if (!genVConsole) return;

  const isShowVConsole = getUrlPara('vconsole') || '';
  const noDelay = sessionStorage.getItem(V_CONSOLE_NO_DELAY.KEY);


  genVConsole({
    immediateShow: isShowVConsole === 'true'
      || isTestEnv()
      || noDelay === V_CONSOLE_NO_DELAY.VALUE,
    hide: false,
    asyncConfirmFunc: checkIsDevList,
    vConsoleConfig: getConfig('vConsole'),
  });
}


export function loadVConsoleFromExternal() {
  const isShowVConsole = getUrlPara('vconsole') || '';
  const isVConsoleDisable = !!getConfig('vConsole.disable');
  const hide = isShowVConsole === 'false' || !UserInfo.tipUid() || isVConsoleDisable;

  if (hide) return;

  loader(VCONSOLE_HELPER_SCRIPT, () => {
    innerLoadVConsole();
  });
}

优化效果,使用之后原文件大小减少27.22KBgzip大小减少10.78KB

# 更新日志

点此查看

Last Updated: 2025/1/15 14:15:00