erratic-gate/build.js

45 lines
1.2 KiB
JavaScript
Raw Normal View History

2023-10-29 04:54:24 +01:00
import * as esbuild from 'esbuild'
import { htmlPlugin } from '@craftamap/esbuild-plugin-html'
import { sassPlugin } from 'esbuild-sass-plugin'
2023-10-29 05:46:53 +01:00
import * as fs from 'fs'
2023-10-29 04:54:24 +01:00
const serve = process.env.ESBUILD_SERVE === '1'
const ctx = await esbuild.context({
entryPoints: ['src/index.ts'],
2023-10-29 05:46:53 +01:00
minify: !serve,
bundle: true,
2023-10-29 04:54:24 +01:00
metafile: true,
splitting: true,
2023-10-29 05:46:53 +01:00
outdir: 'dist',
2023-10-29 04:54:24 +01:00
format: 'esm',
2023-10-29 05:46:53 +01:00
target: ['es2020'],
assetNames: 'assets/[name]-[hash]',
2023-10-29 04:54:24 +01:00
loader: {
'.svg': 'file'
},
plugins: [
htmlPlugin({
files: [
{
filename: 'index.html',
entryPoints: ['src/index.ts'],
favicon: 'public/favicon.ico',
htmlTemplate: 'public/index.html',
scriptLoading: 'module'
}
]
}),
sassPlugin({})
]
})
if (serve) {
const { port, host } = await ctx.serve({ servedir: 'dist' })
console.log(`Serving on ${host}:${port}`)
2023-10-29 05:46:53 +01:00
} else {
await ctx.rebuild()
await ctx.dispose()
fs.cpSync('./dist/index.html', './dist/404.html') // Needed to please github pages
2023-10-29 04:54:24 +01:00
}