blog/lib/tasks/css.ts

30 lines
1012 B
TypeScript

import postcss, { Result } from "postcss";
import config from "../../postcss.config.ts";
import { dest, fromGlob } from "../rx-utils.ts";
import { lastValueFrom, mergeMap } from "rxjs";
import hashPaths from "../hash.ts";
import File from "vinyl";
import { Buffer } from "node:buffer";
export const css = async () => {
await lastValueFrom(
fromGlob("src/index.css").pipe(
mergeMap(
(file) =>
new Promise<File>((resolve) =>
postcss(config.plugins)
.process(file.contents, { from: file.path })
.then((result: Result) => {
file.contents = Buffer.from(result.css);
file.path = "index.css";
resolve(file);
})
),
),
hashPaths("css.manifest"),
mergeMap(dest("dist/_assets")),
),
);
};