2023-03-31 17:19:07 +03:00
|
|
|
/** @file Entry point for the bundler. */
|
|
|
|
import * as fs from 'node:fs/promises'
|
|
|
|
import * as path from 'node:path'
|
|
|
|
import * as url from 'node:url'
|
|
|
|
|
|
|
|
import * as esbuild from 'esbuild'
|
|
|
|
|
|
|
|
import * as bundler from './esbuild-config'
|
|
|
|
|
|
|
|
// =================
|
|
|
|
// === Constants ===
|
|
|
|
// =================
|
|
|
|
|
|
|
|
export const THIS_PATH = path.resolve(path.dirname(url.fileURLToPath(import.meta.url)))
|
|
|
|
|
|
|
|
// ===============
|
|
|
|
// === Bundler ===
|
|
|
|
// ===============
|
|
|
|
|
2023-05-19 22:55:29 +03:00
|
|
|
/** Clean up old build output and runs the esbuild bundler. */
|
2023-03-31 17:19:07 +03:00
|
|
|
async function bundle() {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
await fs.rm('./build', { recursive: true })
|
|
|
|
} catch {
|
|
|
|
// Ignored.
|
|
|
|
}
|
|
|
|
const opts = bundler.bundlerOptions({
|
|
|
|
outputPath: './build',
|
|
|
|
devMode: false,
|
|
|
|
})
|
|
|
|
opts.entryPoints.push(
|
|
|
|
path.resolve(THIS_PATH, 'src', 'index.html'),
|
|
|
|
path.resolve(THIS_PATH, 'src', 'index.tsx')
|
|
|
|
)
|
2023-05-02 20:48:07 +03:00
|
|
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
|
|
opts.loader = { '.html': 'copy' }
|
2023-03-31 17:19:07 +03:00
|
|
|
await esbuild.build(opts)
|
2023-04-24 15:56:26 +03:00
|
|
|
return
|
2023-03-31 17:19:07 +03:00
|
|
|
} catch (error) {
|
|
|
|
console.error(error)
|
2023-04-13 18:17:32 +03:00
|
|
|
// The error is being re-thrown.
|
|
|
|
// eslint-disable-next-line no-restricted-syntax
|
2023-03-31 17:19:07 +03:00
|
|
|
throw error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void bundle()
|