UNPKG

one

Version:

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

65 lines 2.64 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: !0 }); }, __copyProps = (to, from, except, desc) => { if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); return to; }; var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod); var devtoolsPlugin_exports = {}; __export(devtoolsPlugin_exports, { DEVTOOLS_VIRTUAL_ID: () => DEVTOOLS_VIRTUAL_ID, createDevtoolsPlugin: () => createDevtoolsPlugin }); module.exports = __toCommonJS(devtoolsPlugin_exports); var import_node_fs = require("node:fs"), import_resolve = require("@vxrn/resolve"); const DEVTOOLS_VIRTUAL_ID = "/@one/dev.js"; function createDevtoolsPlugin(options = {}) { const { includeUI = !0 } = options; return { name: "one-devtools", apply: "serve", // only in dev configureServer(server) { server.middlewares.use(async (req, res, next) => { if (req.url === DEVTOOLS_VIRTUAL_ID) { try { const devEntryPath = (0, import_resolve.resolvePath)("one/devtools/dev.mjs"); let code = (0, import_node_fs.readFileSync)(devEntryPath, "utf-8").replace("import './devtools.mjs'", "").replace("import './source-inspector.mjs'", ""); if (includeUI) { const devtoolsPath = (0, import_resolve.resolvePath)("one/devtools/devtools.mjs"), sourceInspectorPath = (0, import_resolve.resolvePath)("one/devtools/source-inspector.mjs"), devtools = (0, import_node_fs.readFileSync)(devtoolsPath, "utf-8"), sourceInspector = (0, import_node_fs.readFileSync)(sourceInspectorPath, "utf-8"); code = `${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(); }); } }; }