UNPKG

agile-core

Version:

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

2 lines (1 loc) 2.33 kB
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("url"),n=require("path"),r=require("glob"),t=require("ts-deepmerge");var i="undefined"!=typeof document?document.currentScript:null;const o=e.fileURLToPath("undefined"==typeof document?require("url").pathToFileURL(__filename).href:i&&"SCRIPT"===i.tagName.toUpperCase()&&i.src||new URL("plugin.cjs.js",document.baseURI).href),u=n.dirname(o);function a(e){return{name:"aui-vue-plugin",enforce:"post",transform(r,t){if(t.endsWith(".aui.vue")){const i=n.basename(t).replace(".aui.vue",""),o=r.split("export default"),u=`\nconst __aui_comp_define__ = ${o.pop()};\nimport __aui_como_core__ from '${e.coreAlias?e.coreAlias:"agile-core"}';\nif(!__aui_comp_define__.name) {\n __aui_comp_define__.name = '${i}';\n}\nexport const componentStructure = __aui_comp_define__;\nexport default __aui_como_core__.define(__aui_comp_define__);\n`;return{code:o.join("export default")+u}}return null}}}const s="Comp",c="// insert";function f(e){const n="virtual:aui-config",r="\0"+n;return{name:"aui-config-plugin",resolveId(e){if(e===n)return r},load(n){if(n===r){const n=t.merge({tagPrefix:"aui",buildTime:(new Date).toISOString()},e||{});return`export default ${JSON.stringify(n)}`}}}}exports.getAuiConfig=function(e){const i=(null==(e=t.merge({tagPrefix:"aui"},e||{}))?void 0:e.tagPrefix)||"aui";return{userConfig:{plugins:[{name:"aui-export-plugin",enforce:"pre",transform(e,t){if(t.endsWith(".export.aui.ts")){if(-1===e.indexOf(c))throw new Error(`.export.aui.ts文件必须包含[ ${c} ]标记`);const i=n.dirname(t),o=r.glob.sync("**/*.aui.vue",{cwd:i});if(0===o.length)return null;const u=[];return o.forEach((e,r)=>{const t=n.join(i,e).replace(/\\/g,"/");u.push(`import ${s}${r} from '${t}';`),u.push(`import {componentStructure as ${s}${r}_${r} } from '${t}';`)}),u.push(e.replace(c,function(e){const n=[];return e.forEach((e,r)=>{n.push(`[${s}${r}_${r}.name]: ${s}${r}`)}),n.join(", ")}(o))),{code:u.join("\n")}}return null}},a(e),f(e)],resolve:{alias:{"@auicore":n.resolve(u,"./core")},extensions:[".js",".ts",".jsx",".tsx",".json",".cjs.js",".es.js"]},define:{__AUI_CONFIG__:JSON.stringify(t.merge({tagPrefix:"aui",buildTime:(new Date).toISOString()},e||{}))}},isCustomElement:e=>e.startsWith(`${i}-`)}};//# sourceMappingURL=plugin.cjs.js.map