2024-07-19 13:12:45 +00:00
|
|
|
import { replaceInFileSync } from "replace-in-file";
|
|
|
|
import fs from "fs";
|
2024-07-19 15:26:44 +00:00
|
|
|
import postcss from "postcss";
|
|
|
|
import cssnanoPlugin from "cssnano";
|
2024-07-19 15:43:10 +00:00
|
|
|
// @ts-expect-error TS7016 We don't care about the types, if it doesn't work that's fine
|
|
|
|
import postcssNesting from "postcss-nesting";
|
2024-07-19 13:12:45 +00:00
|
|
|
|
2024-07-19 15:26:44 +00:00
|
|
|
const originalCss = fs
|
2024-07-19 13:12:45 +00:00
|
|
|
.readFileSync("src/internal/ui/static-styles.css", "utf8")
|
|
|
|
.replaceAll("\r", "");
|
|
|
|
|
2024-07-19 15:26:44 +00:00
|
|
|
const processor = postcss([
|
2024-07-19 15:43:10 +00:00
|
|
|
postcssNesting,
|
2024-07-19 15:26:44 +00:00
|
|
|
cssnanoPlugin({
|
|
|
|
preset: ["advanced", { autoprefixer: { add: true } }],
|
|
|
|
}),
|
|
|
|
]);
|
|
|
|
processor
|
|
|
|
.process(originalCss, { from: "src/internal/ui/static-styles.css" })
|
|
|
|
.then((result) => {
|
|
|
|
replaceInFileSync({
|
|
|
|
files: "dist/**",
|
|
|
|
from: [/"\s*\/\*\s*%STATIC_STYLES_CSS%\s*\*\/\s*"/g],
|
|
|
|
to: [JSON.stringify(result.css)],
|
|
|
|
});
|
|
|
|
});
|