-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Jonathan Dahan <[email protected]> Co-authored-by: Alex Ruddick <[email protected]>
- Loading branch information
1 parent
d28d2c3
commit 38ec469
Showing
6 changed files
with
1,898 additions
and
3,037 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { context, build } from 'esbuild'; | ||
import inlineWorker from 'esbuild-plugin-inline-worker'; | ||
import { htmlPlugin as html } from '@craftamap/esbuild-plugin-html'; | ||
|
||
const buildOptions = { | ||
entryPoints: ['src/ui.tsx'], | ||
bundle: true, | ||
platform: 'browser', | ||
target: 'es2020', | ||
minify: true, | ||
sourcemap: true, | ||
metafile: true, | ||
logLevel: 'debug', | ||
outdir: 'dist/ui', | ||
tsconfig: 'tsconfig.web.json', | ||
loader: { '.svg': 'file' }, | ||
define: { | ||
IS_WEB: process.env.IS_WEB ?? '0', | ||
}, | ||
plugins: [ inlineWorker(), | ||
html({ | ||
files: [{ | ||
entryPoints: [ 'src/ui.tsx'], | ||
filename: 'index.html', | ||
htmlTemplate: 'src/index.html', | ||
scriptLoading: 'defer', | ||
}] | ||
}) | ||
], | ||
resolveExtensions: ['.js', '.ts', '.tsx', '.svg', '.worker.js'], | ||
}; | ||
|
||
(async () => { | ||
try { | ||
if (process.env.BUILD_MODE === 'development') { | ||
// enables live-reloading | ||
const ctx = await context({ | ||
...buildOptions, | ||
banner: { js: "new EventSource('/esbuild').addEventListener('change', () => location.reload());" } | ||
}) | ||
await ctx.watch(); | ||
const { host, port } = await ctx.serve({servedir: 'dist/ui', port: 9080 }); | ||
console.log(`http://${host}:${port}`) | ||
} else { | ||
await build(buildOptions); | ||
} | ||
} catch (error) { | ||
console.error(error); | ||
process.exit(1); | ||
} | ||
})(); | ||
|
Oops, something went wrong.