UNPKG

@devup-ui/webpack-plugin

Version:

Zero Config, Zero FOUC, Zero Runtime, CSS in JS Preprocessor

56 lines (55 loc) 1.29 kB
import { writeFile as s } from "node:fs/promises"; import { relative as n, dirname as y, join as p, basename as C } from "node:path"; import { codeExtract as S, getCss as $, exportSheet as b, exportClassMap as k, exportFileMap as D } from "@devup-ui/wasm"; const B = function(u) { const { watch: a, package: h, cssDir: r, sheetFile: f, classMapFile: d, fileMapFile: m, singleCss: g } = this.getOptions(), o = this.async(), c = this.resourcePath; try { let e = n(y(c), r).replaceAll("\\", "/"); const F = n(process.cwd(), c); e.startsWith("./") || (e = `./${e}`); const { code: x, css: M = "", map: i, cssFile: l, updatedBaseStyle: P } = S( F, u.toString(), h, e, g, !1, !0 ), v = i ? JSON.parse(i) : null, t = []; if (P && t.push( s(p(r, "devup-ui.css"), $(null, !1), "utf-8") ), l) { const w = `${this.resourcePath} ${Date.now()}`; t.push( s( p(r, C(l)), a ? `/* ${w} */` : M ) ), a && t.push( s(f, b()), s(d, k()), s(m, D()) ); } Promise.all(t).catch(console.error).finally(() => o(null, x, v)); } catch (e) { o(e); } }; export { B as default };