Skip to content

Commit 21b147a

Browse files
authored
Remove PostCSS and move to Lightning CSS (hestiacp#3820)
* Remove postcss and move to lightningcss * Remove non-standard `size` property
1 parent 374e9fb commit 21b147a

File tree

5 files changed

+4201
-6820
lines changed

5 files changed

+4201
-6820
lines changed

build.js

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
// Build JS and CSS using esbuild and PostCSS
55
import { promises as fs } from 'node:fs';
66
import path from 'node:path';
7+
import browserslist from 'browserslist';
78
import esbuild from 'esbuild';
8-
import postcss from 'postcss';
9-
import postcssConfig from './postcss.config.js';
9+
import * as lightningcss from 'lightningcss';
1010

1111
// Packages to build but exclude from bundle
1212
const externalPackages = ['chart.js/auto', 'alpinejs/dist/cdn.min.js'];
@@ -69,11 +69,39 @@ async function processCSS(inputFile, outputFile) {
6969
try {
7070
await ensureDir(path.dirname(outputFile));
7171
const css = await fs.readFile(inputFile);
72-
const result = await postcss(postcssConfig.plugins).process(css, {
73-
from: inputFile,
74-
to: outputFile,
72+
const bundle = await lightningcss.bundleAsync({
73+
filename: inputFile,
74+
sourceMap: true,
75+
code: Buffer.from(css),
76+
minify: true,
77+
targets: lightningcss.browserslistToTargets(browserslist()),
78+
drafts: { customMedia: true, nesting: true },
79+
visitor: {
80+
Url: (node) => {
81+
// Fix relative paths for webfonts
82+
if (node.url.startsWith('../webfonts/')) {
83+
return {
84+
url: node.url.replace('../webfonts/', '/webfonts/'),
85+
loc: node.loc,
86+
};
87+
}
88+
return node;
89+
},
90+
},
91+
resolver: {
92+
resolve(specifier, from) {
93+
if (!specifier.endsWith('.css')) {
94+
specifier += '.css';
95+
}
96+
if (specifier.startsWith('node:')) {
97+
return `node_modules/${specifier.replace('node:', '')}`;
98+
}
99+
return `${path.dirname(from)}/${specifier}`;
100+
},
101+
},
75102
});
76-
await fs.writeFile(outputFile, result.css);
103+
await fs.writeFile(outputFile, bundle.code);
104+
await fs.writeFile(`${outputFile}.map`, bundle.map);
77105
console.log(`✅ CSS build completed for ${inputFile}`);
78106
} catch (error) {
79107
console.error(`❌ Error processing CSS for ${inputFile}:`, error);

0 commit comments

Comments
 (0)