diff options
| author | Elizabeth Hunt <me@liz.coffee> | 2025-12-14 16:39:17 -0800 |
|---|---|---|
| committer | Elizabeth Hunt <me@liz.coffee> | 2025-12-14 16:39:17 -0800 |
| commit | 613632f3a8fccb998147e46d0e751ca4afc66544 (patch) | |
| tree | 609c21fb12b95d54c3cdce4c20d02c152dbd81e2 /esbuild.config.js | |
| parent | e033a8fd8ce3fbe92ef87ca662ac6785d4ec9b7b (diff) | |
| download | adelie-613632f3a8fccb998147e46d0e751ca4afc66544.tar.gz adelie-613632f3a8fccb998147e46d0e751ca4afc66544.zip | |
Fixes
Diffstat (limited to 'esbuild.config.js')
| -rw-r--r-- | esbuild.config.js | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/esbuild.config.js b/esbuild.config.js new file mode 100644 index 0000000..1a7e09b --- /dev/null +++ b/esbuild.config.js @@ -0,0 +1,60 @@ +import esbuild from 'esbuild'; +import fs from 'fs-extra'; + +const production = process.env.NODE_ENV === 'production'; + +async function buildJS() { + await esbuild.build({ + entryPoints: ['src/ts/script.ts'], + 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'); + html = html.replace(/ASSET_BASE_PLACEHOLDER/g, ''); + 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(); |
