blog/lib/tasks/css.ts

31 lines
1.0 KiB
TypeScript
Raw Normal View History

2024-06-26 21:42:33 +00:00
import postcss, { Result } from "postcss";
2024-06-27 04:22:58 +00:00
import config from "../../postcss.config.ts";
import { dest, fromGlob } from "../rx-utils.ts";
2024-06-27 01:36:05 +00:00
import { lastValueFrom, mergeMap } from "rxjs";
2024-06-27 04:22:58 +00:00
import hashPaths from "../hash.ts";
2024-06-27 08:06:39 +00:00
import { VFile } from "vfile";
2024-06-27 04:45:39 +00:00
export const css = async () => {
await lastValueFrom(
2024-06-27 01:36:05 +00:00
fromGlob("src/index.css").pipe(
2024-06-27 01:28:17 +00:00
mergeMap(
2024-06-26 21:42:33 +00:00
(file) =>
2024-06-27 08:06:39 +00:00
new Promise<VFile>((resolve) =>
2024-06-26 21:42:33 +00:00
postcss(config.plugins)
2024-06-27 08:06:39 +00:00
.process(file.value, { from: file.path })
2024-06-26 21:42:33 +00:00
.then((result: Result) => {
2024-06-27 08:06:39 +00:00
const encoder = new TextEncoder();
file.value = encoder.encode(result.css);
2024-06-26 21:42:33 +00:00
file.path = "index.css";
resolve(file);
2024-06-27 04:22:58 +00:00
})
2024-06-26 21:42:33 +00:00
),
),
hashPaths("css.manifest"),
2024-06-27 01:28:17 +00:00
mergeMap(dest("dist/_assets")),
2024-06-26 21:42:33 +00:00
),
2024-06-27 04:45:39 +00:00
);
};