@devup-ui/vite-plugin
Version:
Zero Config, Zero FOUC, Zero Runtime, CSS in JS Preprocessor
2 lines (1 loc) • 2.33 kB
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("node:fs"),w=require("node:fs/promises"),l=require("node:path"),c=require("@devup-ui/wasm"),m=require("vite");function y(e){var s;if(i.existsSync(e.interfacePath)||i.mkdirSync(e.interfacePath),i.existsSync(e.devupPath)){c.registerTheme((s=JSON.parse(i.readFileSync(e.devupPath,"utf-8")))==null?void 0:s.theme);const u=c.getThemeInterface(e.package,"DevupThemeColors","DevupThemeTypography","DevupTheme");u&&i.writeFileSync(l.join(e.interfacePath,"theme.d.ts"),u,{encoding:"utf-8"})}i.existsSync(e.cssFile)||i.writeFileSync(e.cssFile,"",{encoding:"utf-8"}),i.writeFileSync(l.join(e.interfacePath,".gitignore"),"*",{encoding:"utf-8"})}let f="";function T({package:e="@devup-ui/react",devupPath:s="devup.json",interfacePath:u="df",cssFile:a=l.resolve(u,"devup-ui.css"),extractCss:d=!0,debug:v=!1,include:g=[]}={}){c.setDebug(v);try{y({package:e,cssFile:a,devupPath:s,interfacePath:u})}catch(t){console.error(t)}const h=c.getDefaultTheme();return h&&JSON.stringify(h),{name:"devup-ui",config(){const t=c.getDefaultTheme(),r={};t&&(r["process.env.DEVUP_UI_DEFAULT_THEME"]=JSON.stringify(t));const n={server:{watch:{ignored:[`!${s}`]}},define:r,optimizeDeps:{exclude:g}};return d&&(n.build={rollupOptions:{output:{manualChunks(o){if(o.startsWith("devup-ui.css"))return"devup-ui.css"}}}}),n},apply(){return!0},watchChange(t){if(l.resolve(t)===l.resolve(s)&&i.existsSync(s))try{y({package:e,cssFile:a,devupPath:s,interfacePath:u})}catch(r){console.error(r)}},resolveId(t){if(m.normalizePath(t)===m.normalizePath(a))return`devup-ui.css?t=${Date.now().toString()+f.length}`},load(t){if(t.split("?")[0]==="devup-ui.css")return f=c.getCss()},enforce:"pre",async transform(t,r){if(!d)return;const n=r.split("?")[0];if((g.length?new RegExp(`node_modules(?!(${g.map(D=>`.*${D}`).join("|").replaceAll("/","[\\/\\\\_]")})([\\/\\\\.]|$))`).test(n):r.includes("node_modules"))||!/\.(tsx|ts|js|mjs|jsx)$/i.test(n))return;const{code:o,css:p,map:S}=c.codeExtract(n,t,e,a);return p&&f.length<p.length&&(f=p,await w.writeFile(a,`/* ${r} ${Date.now()} */`,{encoding:"utf-8"})),{code:o,map:S}},async generateBundle(t,r){if(!d)return;const n=Object.keys(r).find(o=>o.includes("devup-ui")&&o.endsWith(".css"));n&&"source"in r[n]&&(r[n].source=f)}}}exports.DevupUI=T;