Skip to content

Commit

Permalink
Migrate from webpack to esbuild.
Browse files Browse the repository at this point in the history
Co-authored-by: Jonathan Dahan <[email protected]>
Co-authored-by: Alex Ruddick <[email protected]>
  • Loading branch information
3 people committed Oct 26, 2023
1 parent d28d2c3 commit 38ec469
Show file tree
Hide file tree
Showing 6 changed files with 1,898 additions and 3,037 deletions.
52 changes: 52 additions & 0 deletions build.mjs
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);
}
})();

Loading

0 comments on commit 38ec469

Please sign in to comment.