forked from Ragudos/todo-app-frontend-mentor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.config.css.mjs
52 lines (48 loc) · 1.57 KB
/
esbuild.config.css.mjs
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
43
44
45
46
47
48
49
50
51
52
import esbuild from "esbuild";
import fs from "node:fs";
import path from "node:path";
import url from "url";
import { sassPlugin } from "esbuild-sass-plugin";
import autoprefixer from "autoprefixer";
import postcssPreserEnv from "postcss-preset-env"
import postcss from "postcss";
const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
const args = process.argv;
const isWatch = args[2]?.trim() == "--watchmode";
const mode = isWatch ? "context" : "build";
try {
const ctx = await esbuild[mode]({
bundle: true,
minify: isWatch ? false : true,
metafile: true,
format: "esm",
platform: "node",
entryPoints: [path.resolve(__dirname, "./src/styles/*.scss")],
outdir: path.resolve(__dirname, isWatch ? "./dev-build" : "./public/build"),
entryNames: "[dir]/styles/[name]",
plugins: [
sassPlugin({
async transform(source, _resolveDir) {
const { css } = await postcss([
autoprefixer,
postcssPreserEnv({
stage: 0
})
]).process(source, {
from: "*.scss",
to: "*.css"
});
return css;
}
})
]
});
if (isWatch) {
ctx.watch();
} else {
fs.writeFileSync(path.resolve(__dirname, "./public/build/css.meta.json"), JSON.stringify(ctx.metafile));
}
} catch (err) {
console.error(err);
process.exit(1);
}