1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-10-30 21:23:00 +00:00

Small cleanup to our web build scripts

- Update to Rollup 4.x
 - Replace terser and postcss with swc and lightningcss. This is
   definitely more code for us to write (maybe I should turn them into
   proper plugins we can depend on), but both speedier and fewer
   dependencies.
 - Drop dependency on glob - we can get away with fs.readdir for what we
   needed it for.
This commit is contained in:
Jonathan Coates
2023-10-08 13:14:02 +01:00
parent ab785a0906
commit 6ec34b42e5
5 changed files with 719 additions and 2025 deletions

View File

@@ -11,7 +11,6 @@
* Yes, this would be so much nicer with next.js.
*/
import fs from "fs/promises";
import { glob } from "glob";
import path from "path";
import { type JSX, h } from "preact";
import renderToStaticMarkup from "preact-render-to-string";
@@ -54,12 +53,15 @@ import { type DataExport, WithExport } from "./components/WithExport";
const dataExport = JSON.parse(await fs.readFile(dataFile, "utf-8")) as DataExport;
for (const file of await glob(sourceDir + "/**/*.html")) {
const contents = await fs.readFile(file, "utf-8");
for (const file of await fs.readdir(sourceDir, { withFileTypes: true, recursive: true })) {
if(!file.isFile() || !file.name.endsWith(".html")) continue;
const sourcePath = path.join(file.path, file.name);
const contents = await fs.readFile(sourcePath, "utf-8");
const { result } = await processor.process(contents);
const outputPath = path.resolve(outputDir, path.relative(sourceDir, file));
const outputPath = path.resolve(outputDir, path.relative(sourceDir, sourcePath));
await fs.mkdir(path.dirname(outputPath), { recursive: true });
await fs.writeFile(outputPath, "<!doctype HTML>" + renderToStaticMarkup(<WithExport data={dataExport}>{result}</WithExport>));
}