mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 10:41:25 +08:00

Introduces PostCSS at the end of our CSS compilation pipeline. For now, just adds autoprefixer and light-dark polyfill.
45 lines
1.1 KiB
JavaScript
45 lines
1.1 KiB
JavaScript
import postcssLightDark from "@csstools/postcss-light-dark-function";
|
|
import autoprefixer from "autoprefixer";
|
|
import postcss from "postcss";
|
|
import { browsers } from "../discourse/config/targets";
|
|
import postcssVariablePrefixer from "./postcss-variable-prefixer";
|
|
|
|
const postCssProcessor = postcss([
|
|
autoprefixer({
|
|
overrideBrowserslist: browsers,
|
|
}),
|
|
postcssLightDark,
|
|
postcssVariablePrefixer(),
|
|
]);
|
|
let lastPostcssError, lastPostcssResult;
|
|
|
|
globalThis.postCss = async function (css, map, sourcemapFile) {
|
|
try {
|
|
const rawResult = await postCssProcessor.process(css, {
|
|
from: "input.css",
|
|
to: "output.css",
|
|
map: {
|
|
prev: map,
|
|
inline: false,
|
|
absolute: false,
|
|
annotation: sourcemapFile,
|
|
},
|
|
});
|
|
lastPostcssResult = [rawResult.css, rawResult.map?.toString()];
|
|
} catch (e) {
|
|
lastPostcssError = e;
|
|
}
|
|
};
|
|
|
|
globalThis.getPostCssResult = function () {
|
|
const error = lastPostcssError;
|
|
const result = lastPostcssResult;
|
|
|
|
lastPostcssError = lastPostcssResult = null;
|
|
|
|
if (error) {
|
|
throw error;
|
|
}
|
|
return result;
|
|
};
|