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
53
54
55
56
57
58
59
60
61
|
import {
browserslistToTargets,
bundleAsync,
transform,
} from "npm:lightningcss@1.21.7";
import browserslist from "npm:browserslist";
import { dirname } from "std/path/dirname.ts";
const input = Deno.args[0],
output = Deno.args[1] ?? input.replace("src/", "dist/"),
outputMin = output.replace(/.css$/i, ".min.css");
// Compile
const compile = await bundleAsync({
filename: input,
drafts: { nesting: true },
errorRecovery: true,
minify: false,
targets: browserslistToTargets(
browserslist(">= 0.25%"),
),
});
// Show errors
for (
const { loc: { column, line, filename }, type, message } of compile.warnings
) {
console.warn(
`\n%c%s%c:%c%s%c:%c%s%c\n%s %c%s`,
"color: #ff0",
filename,
"color: #066",
"color: #099",
line,
"color: #066",
"color: #099",
column,
"font-weight: bold",
message,
"color: grey",
type,
);
}
await Deno.mkdir(dirname(output), { recursive: true });
await Deno.writeFile(output, compile.code);
// Minify
const minify = transform({
code: compile.code,
filename: output,
drafts: { nesting: true },
errorRecovery: true,
minify: true,
});
await Deno.mkdir(dirname(outputMin), { recursive: true });
await Deno.writeFile(outputMin, minify.code);
|