UNPKG

agile-core

Version:

Agile Core - A powerful component based micro front-end framework

65 lines (64 loc) 2.64 kB
import { fileURLToPath as e } from "url"; import n, { dirname as r } from "path"; import { glob as o } from "glob"; import { merge as t } from "ts-deepmerge"; const i = r(e(import.meta.url)); function u(e2) { return { name: "aui-vue-plugin", enforce: "post", transform(r2, o2) { if (o2.endsWith(".aui.vue")) { const t2 = n.basename(o2).replace(".aui.vue", ""), i2 = r2.split("export default"), u2 = ` const __aui_comp_define__ = ${i2.pop()}; import __aui_como_core__ from '${e2.coreAlias ? e2.coreAlias : "agile-core"}'; if(!__aui_comp_define__.name) { __aui_comp_define__.name = '${t2}'; } export const componentStructure = __aui_comp_define__; export default __aui_como_core__.define(__aui_comp_define__); `; return { code: i2.join("export default") + u2 }; } return null; } }; } const a = "Comp"; const s = "// insert"; function c() { return { name: "aui-export-plugin", enforce: "pre", transform(e2, r2) { if (r2.endsWith(".export.aui.ts")) { if (-1 === e2.indexOf(s)) throw new Error(`.export.aui.ts文件必须包含[ ${s} ]标记`); const t2 = n.dirname(r2), i2 = o.sync("**/*.aui.vue", { cwd: t2 }); if (0 === i2.length) return null; const u2 = []; return i2.forEach((e3, r3) => { const o2 = n.join(t2, e3).replace(/\\/g, "/"); u2.push(`import ${a}${r3} from '${o2}';`), u2.push(`import {componentStructure as ${a}${r3}_${r3} } from '${o2}';`); }), u2.push(e2.replace(s, function(e3) { const n2 = []; return e3.forEach((e4, r3) => { n2.push(`[${a}${r3}_${r3}.name]: ${a}${r3}`); }), n2.join(", "); }(i2))), { code: u2.join("\n") }; } return null; } }; } function _(e2) { const n2 = "virtual:aui-config", r2 = "\0" + n2; return { name: "aui-config-plugin", resolveId(e3) { if (e3 === n2) return r2; }, load(n3) { if (n3 === r2) { const n4 = t({ tagPrefix: "aui", buildTime: (/* @__PURE__ */ new Date()).toISOString() }, e2 || {}); return `export default ${JSON.stringify(n4)}`; } } }; } function getAuiConfig(e2) { e2 = t({ tagPrefix: "aui" }, e2 || {}); const r2 = (e2 == null ? void 0 : e2.tagPrefix) || "aui"; return { userConfig: { plugins: [c(), u(e2), _(e2)], resolve: { alias: { "@auicore": n.resolve(i, "./core") }, extensions: [".js", ".ts", ".jsx", ".tsx", ".json", ".cjs.js", ".es.js"] }, define: { __AUI_CONFIG__: JSON.stringify(t({ tagPrefix: "aui", buildTime: (/* @__PURE__ */ new Date()).toISOString() }, e2 || {})) } }, isCustomElement: (e3) => e3.startsWith(`${r2}-`) }; } export { getAuiConfig }; //# sourceMappingURL=plugin.es.js.map