UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

50 lines (49 loc) 1.88 kB
import { readFileSync } from "fs"; import path from "path"; import { resolvePath } from "@vxrn/resolve"; var DEVTOOLS_VIRTUAL_ID = "/@one/dev.js"; function createDevtoolsPlugin() { var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}; var { includeUI = true } = options; return { name: "one-devtools", apply: "serve", // only in dev configureServer(server) { server.middlewares.use(async function (req, res, next) { if (req.url === DEVTOOLS_VIRTUAL_ID) { try { var devEntryPath = resolvePath("one/devtools/dev.mjs"); var devEntry = readFileSync(devEntryPath, "utf-8"); var code = devEntry.replace("import './devtools.mjs'", "").replace("import './source-inspector.mjs'", ""); if (includeUI) { var devtoolsPath = resolvePath("one/devtools/devtools.mjs"); var sourceInspectorPath = resolvePath("one/devtools/source-inspector.mjs"); var devtools = readFileSync(devtoolsPath, "utf-8"); var sourceInspector = readFileSync(sourceInspectorPath, "utf-8"); var projectName = path.basename(process.cwd()); code = `window.__oneProjectRoot="${projectName}"; ${code} ${devtools} ${sourceInspector}`; } res.setHeader("Content-Type", "application/javascript"); res.setHeader("Cache-Control", "no-store"); res.end(code); return; } catch (e) { console.error("[one] Failed to load devtools script:", e); } res.setHeader("Content-Type", "application/javascript"); res.end("// devtools failed to load"); return; } next(); }); } }; } export { DEVTOOLS_VIRTUAL_ID, createDevtoolsPlugin }; //# sourceMappingURL=devtoolsPlugin.native.js.map