-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
32 lines (26 loc) · 854 Bytes
/
build.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
import fs from "node:fs";
import path from "node:path";
import * as sass from "sass";
const DIST_DIR = "dist";
const SRC_DIR = "src";
const allFiles = fs.readdirSync(SRC_DIR, { recursive: true });
const files = allFiles.filter((e) => e.endsWith(".scss"));
const dirs = allFiles.filter((e) => !e.endsWith(".scss"));
fs.rmSync(DIST_DIR, { recursive: true });
for (const dir of dirs) {
fs.mkdirSync(path.join(DIST_DIR, dir), { recursive: true });
}
for (const file of files) {
const { css } = await sass
.compileAsync(path.join(SRC_DIR, file))
.catch((e) => {
console.log(e.message);
process.exit(1);
});
const filePath = path.join(DIST_DIR, file).replace("scss", "css");
fs.writeFileSync(filePath, css);
}
fs.writeFileSync(
path.join(DIST_DIR, "index.css"),
files.map((e) => `@import "${e.replace("scss", "css")}";`).join("\n"),
);