@vue-macros/jsx-directive
Version:
jsxDirective feature from Vue Macros.
60 lines (57 loc) • 1.42 kB
JavaScript
import {
helperPrefix,
transformJsxDirective,
withDefaultsHelperId,
with_defaults_default
} from "./chunk-AAKT5ACG.js";
// src/core/plugin.ts
import {
createFilter,
detectVueVersion,
FilterFileType,
getFilterPattern,
normalizePath,
REGEX_NODE_MODULES,
REGEX_SETUP_SFC
} from "@vue-macros/common";
function resolveOptions(options, framework) {
const version = options.version || detectVueVersion();
const include = getFilterPattern(
[FilterFileType.VUE_SFC, FilterFileType.SRC_FILE],
framework
);
return {
include,
exclude: [REGEX_NODE_MODULES, REGEX_SETUP_SFC],
...options,
prefix: options.prefix ?? "v-",
lib: options.lib ?? "vue",
version
};
}
var name = "unplugin-vue-jsx-directive";
var plugin = (userOptions = {}, { framework } = { framework: "vite" }) => {
const options = resolveOptions(userOptions, framework);
const filter = createFilter(options);
return {
name,
enforce: "pre",
resolveId(id) {
if (normalizePath(id).startsWith(helperPrefix)) return id;
},
loadInclude(id) {
return normalizePath(id).startsWith(helperPrefix);
},
load(_id) {
const id = normalizePath(_id);
if (id === withDefaultsHelperId) return with_defaults_default;
},
transformInclude: filter,
transform(code, id) {
return transformJsxDirective(code, id, options);
}
};
};
export {
plugin
};