blog/lib/tasks/css.ts

27 lines
926 B
TypeScript

import postcss, { Result } from "postcss";
import config from "../../postcss.config.js";
import { dest, fromGlob } from "../rx-utils.js";
import { lastValueFrom, mergeMap } from "rxjs";
import hashPaths from "../hash.js";
export const css = () =>
lastValueFrom(
fromGlob("src/index.css").pipe(
mergeMap(
(file) =>
new Promise((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")),
),
);