vite-plugin-debugger
Version:
A vite plugin provide the debugger tools for mobile devices.
76 lines (73 loc) • 2.14 kB
JavaScript
import {
isPackageExists,
readFileContent,
transformCDN
} from "./chunk-UKMVH5MM.js";
// src/plugins/eruda.ts
import { normalizePath } from "vite";
var transformErudaOptions = 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/eruda/prepend-script.js");
injectCodes += `
})(${debug},${JSON.stringify(active)},${JSON.stringify(options)},${JSON.stringify(src || await transformCDN("eruda", cdn))});
`;
tags.push({
tag: "script",
injectTo: "head",
children: injectCodes
});
if (debug !== void 0) {
return {
html,
tags
};
}
};
var transformErudaImport = (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/eruda/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("eruda"), entry } = options;
const entryPath = entry ? (Array.isArray(entry) ? entry : [entry]).map((path) => normalizePath(path)) : [];
if (local) {
return {
name: "vite:mobile-devtools:eruda",
transform(code, id) {
if (entryPath.includes(id)) {
return transformErudaImport(code, options);
}
return { code, map: null };
}
};
}
return {
name: "vite:mobile-devtools:eruda",
transformIndexHtml: async (html) => {
return await transformErudaOptions(html, options);
}
};
}
var eruda_default = vDebugger;
export {
vDebugger,
eruda_default
};