diff options
| author | Elizabeth Hunt <me@liz.coffee> | 2025-12-13 17:03:24 -0800 |
|---|---|---|
| committer | Elizabeth Hunt <me@liz.coffee> | 2025-12-13 17:03:24 -0800 |
| commit | 93f80150a1d07cf3ce51447636c7f8cd510832f1 (patch) | |
| tree | eaa4c7cf4d40e8a2dc86b2119894d9e0de10d7f3 /esbuild.config.js | |
| parent | eb14a9b6263a3dd65fc62e1611c6da067a80ca00 (diff) | |
| download | adelie-93f80150a1d07cf3ce51447636c7f8cd510832f1.tar.gz adelie-93f80150a1d07cf3ce51447636c7f8cd510832f1.zip | |
Syntax highlighting and a real repo struct
Diffstat (limited to 'esbuild.config.js')
| -rw-r--r-- | esbuild.config.js | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/esbuild.config.js b/esbuild.config.js new file mode 100644 index 0000000..1bee10c --- /dev/null +++ b/esbuild.config.js @@ -0,0 +1,75 @@ +const esbuild = require('esbuild'); +const fs = require('fs-extra'); +const path = require('path'); + +const production = process.env.NODE_ENV === 'production'; + +async function buildJS() { + await esbuild.build({ + entryPoints: ['src/js/script.js'], + bundle: true, + minify: production, + sourcemap: true, + target: 'es2020', + outfile: 'dist/bundle.js', + }); +} + +async function buildCSS() { + await esbuild.build({ + entryPoints: ['src/css/style.css'], + bundle: true, + minify: production, + sourcemap: true, + loader: { + '.css': 'css', + '.woff2': 'file', + '.png': 'file', + '.svg': 'file', + }, + outfile: 'dist/bundle.css', + }); +} + +async function copyAssets() { + await fs.copy('src/assets', 'dist', { + overwrite: true, + }); +} + +async function processHTML() { + let html = await fs.readFile('src/index.html', 'utf8'); + + const host = process.env.HOST || ''; + const cleanHost = host.replace(/\/$/, ''); + + if (cleanHost) { + html = html.replace(/href="\/bundle\./g, `href="${cleanHost}/bundle.`); + html = html.replace(/src="\/bundle\./g, `src="${cleanHost}/bundle.`); + html = html.replace(/href="\/img\//g, `href="${cleanHost}/img/`); + html = html.replace(/src="\/oneko\//g, `src="${cleanHost}/oneko/`); + } + + await fs.writeFile('dist/index.html', html); +} + +async function clean() { + await fs.remove('dist'); + await fs.ensureDir('dist'); +} + +async function build() { + try { + await clean(); + await Promise.all([ + buildJS(), + buildCSS(), + copyAssets(), + ]); + await processHTML(); + } catch (err) { + process.exit(1); + } +} + +build(); |
