From bae2bac25bbd6b393cfde6bf04486e083033ef6d Mon Sep 17 00:00:00 2001 From: sophie Date: Sat, 11 Jan 2025 15:46:07 +0200 Subject: [PATCH] add a lot more configuration options for more involved projects --- src/plugins/dev.ts | 3 ++- src/plugins/ts-compiler.ts | 13 ++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/plugins/dev.ts b/src/plugins/dev.ts index d8eef98..29b9a69 100644 --- a/src/plugins/dev.ts +++ b/src/plugins/dev.ts @@ -15,7 +15,7 @@ export default class DevPlugin extends Plugin { server!: Server; allConnections: ServerWebSocket[] = []; - constructor(sssg: SSSG) { + constructor(sssg: SSSG, headers: Record) { super(); fs.watch( @@ -71,6 +71,7 @@ export default class DevPlugin extends Plugin { "Pragma": "no-cache", "Expires": "0", "Content-Type": (mime.lookup(type) || "application/octet-stream") + "; charset=utf-8", + ...headers }, }); }, diff --git a/src/plugins/ts-compiler.ts b/src/plugins/ts-compiler.ts index fa62fdf..6b460f4 100644 --- a/src/plugins/ts-compiler.ts +++ b/src/plugins/ts-compiler.ts @@ -9,14 +9,16 @@ export default class TSCompiler extends Plugin { rewriteTriggers = ["ts", "tsx", "jsx"]; renameTo = "js"; longLasting = false; + esbuildOptions: esbuild.BuildOptions; minify = false; - constructor() { + + constructor(minify: boolean, esbuildOptions: esbuild.BuildOptions = {}) { super(); - if (process.argv.includes("--prod")) { - this.minify = true; - } + this.minify = minify; + this.esbuildOptions = esbuildOptions; } + async rewriteFile(file: string, filePath: string) { let result; try { @@ -38,6 +40,7 @@ export default class TSCompiler extends Plugin { bundle: true, outdir: "out", minify: this.minify, + ...this.esbuildOptions }); } catch (e) { console.error(e); @@ -51,7 +54,7 @@ export default class TSCompiler extends Plugin { console.error(element); }); } else { - const output = result.outputFiles[0].contents; + const output = result.outputFiles![0].contents; return new TextDecoder().decode(output); } }