vue-jsx-vapor
Version:
Vapor Mode of Vue JSX
100 lines (97 loc) • 3.57 kB
JavaScript
const require_chunk = require('./chunk-CbDLau6x.cjs');
const require_core = require('./core-DWvzPUZs.cjs');
let _vue_jsx_vapor_macros_raw = require("@vue-jsx-vapor/macros/raw");
_vue_jsx_vapor_macros_raw = require_chunk.__toESM(_vue_jsx_vapor_macros_raw);
let _vue_jsx_vapor_runtime_raw = require("@vue-jsx-vapor/runtime/raw");
let pathe = require("pathe");
let unplugin_utils = require("unplugin-utils");
//#region src/core/ssr.ts
const ssrRegisterHelperId = "/__vue-jsx-ssr-register-helper";
const ssrRegisterHelperCode = `import { useSSRContext } from "vue"\nexport const ssrRegisterHelper = ${ssrRegisterHelper.toString()}`;
/**
* This function is serialized with toString() and evaluated as a virtual
* module during SSR
*/
function ssrRegisterHelper(comp, filename) {
if (typeof comp === "function") comp.__setup = () => {
const ssrContext = useSSRContext();
(ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add(filename);
};
else {
const setup = comp.setup;
comp.setup = (props, ctx) => {
const ssrContext = useSSRContext();
(ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add(filename);
if (setup) return setup(props, ctx);
};
}
}
//#endregion
//#region src/raw.ts
const plugin = (options = {}) => {
let root = "";
let needHMR = false;
let needSourceMap = options.sourceMap || false;
return [...options.macros === false ? [] : options.macros ? (0, _vue_jsx_vapor_macros_raw.default)(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: [
ssrRegisterHelperId,
_vue_jsx_vapor_runtime_raw.propsHelperId,
_vue_jsx_vapor_runtime_raw.vdomHelperId,
_vue_jsx_vapor_runtime_raw.vaporHelperId
] },
handler: (id) => id
},
load: {
filter: { id: [
ssrRegisterHelperId,
_vue_jsx_vapor_runtime_raw.propsHelperId,
_vue_jsx_vapor_runtime_raw.vdomHelperId,
_vue_jsx_vapor_runtime_raw.vaporHelperId
] },
handler(id) {
if (id === ssrRegisterHelperId) return ssrRegisterHelperCode;
if (id === _vue_jsx_vapor_runtime_raw.propsHelperId) return _vue_jsx_vapor_runtime_raw.propsHelperCode;
if (id === _vue_jsx_vapor_runtime_raw.vdomHelperId) return _vue_jsx_vapor_runtime_raw.vdomHelperCode;
if (id === _vue_jsx_vapor_runtime_raw.vaporHelperId) return _vue_jsx_vapor_runtime_raw.vaporHelperCode;
}
},
transform: {
filter: { id: {
include: options?.include || /\.[cm]?[jt]sx$/,
exclude: options?.exclude || /node_modules/
} },
handler(code, id, opt) {
const result = require_core.transformVueJsxVapor(code, opt?.ssr ? (0, unplugin_utils.normalizePath)((0, pathe.relative)(root, id)) : id, options, needSourceMap, needHMR, opt?.ssr);
if (result?.code) return {
code: result.code,
map: result.map ? JSON.parse(result.map) : null
};
}
}
}];
};
var raw_default = plugin;
//#endregion
Object.defineProperty(exports, 'raw_default', {
enumerable: true,
get: function () {
return raw_default;
}
});