UNPKG

one

Version:

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

44 lines (43 loc) 1.06 kB
import { extname } from "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; } var ext = extname(id); var mod = swc.parseSync(code, parseOpts(ext)); var hasUseDom = false; for (var i = 0; i < mod.body.length; ++i) { var item = mod.body[i]; if (item.type === "ExpressionStatement") { if (item.expression.type === "StringLiteral") { if (item.expression.value === "use dom") { hasUseDom = true; break; } } } else {} } if (!hasUseDom) { return; } } }; } var parseOpts = function (ext) { if (ext === ".ts" || ext === ".tsx") { return { syntax: "typescript", tsx: ext.endsWith("x") }; } return { syntax: "ecmascript", jsx: ext.endsWith("x") }; }; export { useDOMPlugin }; //# sourceMappingURL=useDomPlugin.native.js.map