blog/lib/tasks/css.ts

30 lines
1012 B
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";
import File from "vinyl";
import { Buffer } from "node:buffer";
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 04:22:58 +00:00
new Promise<File>((resolve) =>
2024-06-26 21:42:33 +00:00
postcss(config.plugins)
.process(file.contents, { from: file.path })
.then((result: Result) => {
file.contents = Buffer.from(result.css);
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
);
};