@devup-ui/rsbuild-plugin
Version:
Zero Config, Zero FOUC, Zero Runtime, CSS in JS Preprocessor
48 lines (47 loc) • 1.26 kB
JavaScript
import { mkdir as f, writeFile as r } from "node:fs/promises";
import { join as c, resolve as w } from "node:path";
import { codeExtract as v } from "@devup-ui/wasm";
let i = "";
const b = ({
include: s = [],
package: m = "@devup-ui/react",
extractCss: a = !0,
interfacePath: n = "df",
cssFile: t = w(n, "devup-ui.css")
} = {}) => ({
name: "devup-ui-rsbuild-plugin",
async setup(u) {
a && (await f(n, { recursive: !0 }), await r(c(n, ".gitignore"), "*", {
encoding: "utf-8"
}), await r(t, ""), u.transform(
{
test: t
},
() => i
), u.transform(
{
test: /\.(tsx|ts|js|mjs|jsx)$/
},
async ({ code: d, resourcePath: e }) => {
if (s.length ? new RegExp(
`node_modules(?!(${s.map((g) => `.*${g}`).join("|").replaceAll("/", "[\\/\\\\_]")})([\\/\\\\.]|$))`
).test(e) : e.includes("node_modules"))
return d;
const {
code: l,
css: o,
map: p
} = v(e, d, m, t);
return o && i.length < o.length && (i = o, await r(t, `/* ${e} ${Date.now()} */`, {
encoding: "utf-8"
})), {
code: l,
map: p
};
}
));
}
});
export {
b as DevupUIRsbuildPlugin
};