UNPKG

vite-plugin-debugger

Version:

A vite plugin provide the debugger tools for mobile devices.

76 lines (73 loc) 2.17 kB
import { isPackageExists, readFileContent, transformCDN } from "./chunk-UKMVH5MM.js"; // src/plugins/vconsole.ts import { normalizePath } from "vite"; var transformVConsoleOptions = async (html, opts) => { const { debug, active } = opts; const { options, cdn = "jsdelivr", src } = opts.config; const tags = []; let injectCodes = ``; injectCodes += "\n(function(debug,active,options,cdn){\n"; injectCodes += readFileContent("./precompiled/show-or-not.js"); injectCodes += readFileContent("./precompiled/vconsole/prepend-script.js"); injectCodes += ` })(${debug},${JSON.stringify(active)},${JSON.stringify(options)},${JSON.stringify(src || await transformCDN("vConsole", cdn))}); `; tags.push({ tag: "script", injectTo: "head", children: injectCodes }); if (debug !== void 0) { return { html, tags }; } }; var transformVConsoleImport = (code, opts) => { const { debug, active } = opts; const { options = {} } = opts.config; let injectCodes = ``; injectCodes += "\n/* eslint-disable */\n"; injectCodes += "\n(function(debug,active,options){\n"; injectCodes += readFileContent("./precompiled/show-or-not.js"); injectCodes += readFileContent("./precompiled/vconsole/dynamic-import.js"); injectCodes += ` })(${debug},${JSON.stringify(active)},${JSON.stringify(options)}); `; injectCodes += "\n/* eslint-enable */\n"; return { code: `${injectCodes}${code}`, map: null }; }; function vDebugger(options) { const { local = isPackageExists("vconsole"), entry } = options; const entryPath = entry ? (Array.isArray(entry) ? entry : [entry]).map((path) => normalizePath(path)) : []; if (local) { return { name: "vite:mobile-devtools:vconsole", transform(code, id) { if (entryPath.includes(id)) { return transformVConsoleImport(code, options); } return { code, map: null }; } }; } return { name: "vite:mobile-devtools:vconsole", transformIndexHtml: async (html) => { return await transformVConsoleOptions(html, options); } }; } var vconsole_default = vDebugger; export { vDebugger, vconsole_default };