-
Notifications
You must be signed in to change notification settings - Fork 356
/
Copy pathcompile-css.js
42 lines (37 loc) · 1.12 KB
/
compile-css.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import fs from "fs";
import stylus from "stylus";
import postcss from "postcss";
import atImport from "postcss-import";
import inline_svg from "postcss-inline-svg";
import autoprefixer from "autoprefixer";
import cssnano from "cssnano";
console.log("");
console.log("Re-compiling css because vite can't generate production sourcemaps still");
const style = stylus(fs.readFileSync("src/ogs.styl", "utf8"))
.set("filename", "src/ogs.styl")
.set("sourcemap", {
comment: true,
inline: true,
});
style.render((err, css) => {
if (err) {
console.error(err);
return;
}
postcss([atImport(), inline_svg(), autoprefixer(), cssnano()])
.process(css, {
from: "dist/ogs.css",
to: "dist/ogs.min.css",
map: {
inline: false,
prev: style.sourcemap,
},
})
.then((result) => {
fs.writeFileSync("dist/ogs.min.css", result.css);
if (result.map) {
fs.writeFileSync("dist/ogs.min.css.map", result.map.toString());
}
});
});
console.log("Done");