UNPKG

vue-jsx-vapor

Version:
60 lines (58 loc) 2.06 kB
import { t as transformVueJsxVapor } from "./core-F-TBUTIG.js"; import macros from "@vue-jsx-vapor/macros/raw"; import { propsHelperCode, propsHelperId, ssrHelperCode, ssrHelperId, vaporHelperCode, vaporHelperId, vdomHelperCode, vdomHelperId } from "@vue-jsx-vapor/runtime/raw"; import { relative } from "pathe"; import { normalizePath } from "unplugin-utils"; //#region src/raw.ts const plugin = (options = {}) => { let root = ""; let needHMR = false; let needSourceMap = options.sourceMap || false; const helperId = /^\/vue-jsx-vapor\//; return [...options.macros === false ? [] : options.macros ? macros(options.macros === true ? void 0 : options.macros) : [], { enforce: "pre", name: "vue-jsx-vapor", vite: { config(config) { return { define: { __VUE_OPTIONS_API__: config.define?.__VUE_OPTIONS_API__ ?? true, __VUE_PROD_DEVTOOLS__: config.define?.__VUE_PROD_DEVTOOLS__ ?? false, __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: config.define?.__VUE_PROD_HYDRATION_MISMATCH_DETAILS__ ?? false } }; }, configResolved(config) { root = config.root; needHMR = config.command === "serve"; needSourceMap ||= config.command === "serve" || !!config.build.sourcemap; } }, resolveId: { filter: { id: helperId }, handler: (id) => id }, load: { filter: { id: helperId }, handler(id) { if (id === ssrHelperId) return ssrHelperCode; if (id === propsHelperId) return propsHelperCode; if (id === vdomHelperId) return vdomHelperCode; if (id === vaporHelperId) return vaporHelperCode; } }, transform: { filter: { id: { include: options?.include || /\.[cm]?[jt]sx(?=$|[?#])/, exclude: options?.exclude || /node_modules/ } }, handler(code, id, opt) { const result = transformVueJsxVapor(code, opt?.ssr ? normalizePath(relative(root, id)) : id, options, needSourceMap, needHMR, opt?.ssr); if (result?.code) return { code: result.code, map: result.map ? JSON.parse(result.map) : null }; } } }]; }; //#endregion export { plugin as default };