UNPKG

one

Version:

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

71 lines (69 loc) 2.78 kB
"use strict"; 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_fs = require("fs"), import_resolve = require("@vxrn/resolve"), DEVTOOLS_VIRTUAL_ID = "/@one/dev.js"; function createDevtoolsPlugin() { var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, { includeUI = !0 } = 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 = (0, import_resolve.resolvePath)("one/devtools/dev.mjs"), devEntry = (0, import_fs.readFileSync)(devEntryPath, "utf-8"), code = devEntry.replace("import './devtools.mjs'", "").replace("import './source-inspector.mjs'", ""); if (includeUI) { var devtoolsPath = (0, import_resolve.resolvePath)("one/devtools/devtools.mjs"), sourceInspectorPath = (0, import_resolve.resolvePath)("one/devtools/source-inspector.mjs"), devtools = (0, import_fs.readFileSync)(devtoolsPath, "utf-8"), sourceInspector = (0, import_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(); }); } }; } //# sourceMappingURL=devtoolsPlugin.native.js.map