@stylezjs/postcss-plugin
Version:
@stylezjs/postcss-plugin is a PostCSS plugin for integrating `@stylezjs/stylez` to generate static CSS styles. Stylez → 'Z' of Zero Runtime.
9 lines (5 loc) • 1.79 kB
JavaScript
var p=(s=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(s,{get:(o,e)=>(typeof require<"u"?require:o)[e]}):s)(function(s){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+s+'" is not supported')});import{writeFileSync as v}from"node:fs";import S from"autoprefixer";import x from"postcss";import{parse as z}from"postcss-js";import P from"postcss-nested";import f from"fast-glob";import{build as y}from"esbuild";import{existsSync as g,mkdirSync as F,rmSync as w}from"fs";import c from"path";var{glob:d}=f,l="./.tmp";g(l)||F(l,{recursive:!0});var u=async s=>{let o=await d(s),e="esm";for(let t of o){let i=c.join(l,`tmp-${c.basename(t)}.js`);await y({bundle:!0,entryPoints:[t],external:["@stylezjs/stylez"],format:e,minify:!0,outfile:i,platform:"node"}),e==="esm"?await import(c.resolve(i)):p(c.resolve(i)),w(l,{force:!0,recursive:!0})}let r;if(e==="esm"){let{getAllCss:t}=await import("@stylezjs/stylez");r=t()}else{let{getAllCss:t}=p("@stylezjs/stylez");r=t()}return r};var n={duplicatesFound:!1,processed:!1},a=s=>({async Once(o){if(n.duplicatesFound)return;let e=o.first,r=e?.source?.input?.file;if(e?.name==="stylez"&&r?.includes(process.cwd())){if(n.processed){n.duplicatesFound=!0,process.stdout.write(`\u26D4\uFE0F Multiple @stylez files detected. Remove duplicates before processing.
`);return}try{n.processed=!0;let t=await u(s?.patterns??[]);if(n.duplicatesFound)return;o.removeAll();let i=await x([P,S]).process(t,{from:void 0,parser:z});if(i.css.length===0)return;let m=`@stylez;
${i.css}`;v(r,m),process.stdout.write(`\u{1F3A8} Styles saved to: ${r}
`)}catch{process.stdout.write("Issue saving styles")}}},postcssPlugin:"@stylezjs/postcss-plugin"});a.postcss=!0;var B=a;export{B as default};
//# sourceMappingURL=index.mjs.map