UNPKG

one

Version:

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

32 lines (31 loc) 865 B
import { extname } from "node:path"; import * as swc from "@swc/core"; function useDOMPlugin() { return { name: "one-vite-dom-plugin", async transform(code, id, options) { if (!code.includes("use dom")) return; const ext = extname(id), mod = swc.parseSync(code, parseOpts(ext)); let hasUseDom = !1; for (let i = 0; i < mod.body.length; ++i) { const item = mod.body[i]; if (item.type === "ExpressionStatement" && item.expression.type === "StringLiteral" && item.expression.value === "use dom") { hasUseDom = !0; break; } } } }; } const parseOpts = (ext) => ext === ".ts" || ext === ".tsx" ? { syntax: "typescript", tsx: ext.endsWith("x") } : { syntax: "ecmascript", jsx: ext.endsWith("x") }; export { useDOMPlugin }; //# sourceMappingURL=useDomPlugin.js.map