add a lot more configuration options for more involved projects

This commit is contained in:
Soph :3 2025-01-11 15:46:07 +02:00
parent e68ad369e9
commit bae2bac25b
Signed by: sophie
GPG key ID: EDA5D222A0C270F2
2 changed files with 10 additions and 6 deletions

View file

@ -15,7 +15,7 @@ export default class DevPlugin extends Plugin {
server!: Server; server!: Server;
allConnections: ServerWebSocket<number>[] = []; allConnections: ServerWebSocket<number>[] = [];
constructor(sssg: SSSG) { constructor(sssg: SSSG, headers: Record<string, string>) {
super(); super();
fs.watch( fs.watch(
@ -71,6 +71,7 @@ export default class DevPlugin extends Plugin {
"Pragma": "no-cache", "Pragma": "no-cache",
"Expires": "0", "Expires": "0",
"Content-Type": (mime.lookup(type) || "application/octet-stream") + "; charset=utf-8", "Content-Type": (mime.lookup(type) || "application/octet-stream") + "; charset=utf-8",
...headers
}, },
}); });
}, },

View file

@ -9,14 +9,16 @@ export default class TSCompiler extends Plugin {
rewriteTriggers = ["ts", "tsx", "jsx"]; rewriteTriggers = ["ts", "tsx", "jsx"];
renameTo = "js"; renameTo = "js";
longLasting = false; longLasting = false;
esbuildOptions: esbuild.BuildOptions;
minify = false; minify = false;
constructor() {
constructor(minify: boolean, esbuildOptions: esbuild.BuildOptions = {}) {
super(); super();
if (process.argv.includes("--prod")) { this.minify = minify;
this.minify = true; this.esbuildOptions = esbuildOptions;
}
} }
async rewriteFile(file: string, filePath: string) { async rewriteFile(file: string, filePath: string) {
let result; let result;
try { try {
@ -38,6 +40,7 @@ export default class TSCompiler extends Plugin {
bundle: true, bundle: true,
outdir: "out", outdir: "out",
minify: this.minify, minify: this.minify,
...this.esbuildOptions
}); });
} catch (e) { } catch (e) {
console.error(e); console.error(e);
@ -51,7 +54,7 @@ export default class TSCompiler extends Plugin {
console.error(element); console.error(element);
}); });
} else { } else {
const output = result.outputFiles[0].contents; const output = result.outputFiles![0].contents;
return new TextDecoder().decode(output); return new TextDecoder().decode(output);
} }
} }