feat(web): add web demo and polish Lit web components UI and demo tooling
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import * as esbuild from 'esbuild';
|
||||
|
||||
// Shim unused Node.js built-ins that get pulled in by dependencies.
|
||||
const nodeShimPlugin: esbuild.Plugin = {
|
||||
name: 'node-builtins-shim',
|
||||
setup(build) {
|
||||
// Mark node built-ins as empty modules — they are imported but not actually used at runtime.
|
||||
const builtins = ['path', 'fs', 'os', 'crypto', 'stream', 'util', 'events', 'http', 'https', 'net', 'tls', 'child_process', 'url', 'assert', 'buffer', 'tty', 'readline'];
|
||||
const filter = new RegExp(`^(${builtins.join('|')})$`);
|
||||
build.onResolve({ filter }, (args) => ({
|
||||
path: args.path,
|
||||
namespace: 'node-shim',
|
||||
}));
|
||||
build.onLoad({ filter: /.*/, namespace: 'node-shim' }, () => ({
|
||||
contents: 'export default {};',
|
||||
loader: 'js',
|
||||
}));
|
||||
},
|
||||
};
|
||||
|
||||
const buildOptions: esbuild.BuildOptions = {
|
||||
entryPoints: ['demo/demo.web.ts'],
|
||||
bundle: true,
|
||||
format: 'esm',
|
||||
platform: 'browser',
|
||||
outdir: 'demo',
|
||||
sourcemap: true,
|
||||
target: 'es2022',
|
||||
logLevel: 'info',
|
||||
plugins: [nodeShimPlugin],
|
||||
};
|
||||
|
||||
const serve = process.argv.includes('--serve');
|
||||
|
||||
if (serve) {
|
||||
const ctx = await esbuild.context(buildOptions);
|
||||
const { host, port } = await ctx.serve({ servedir: 'demo' });
|
||||
console.log(`\n 🌐 Web demo running at http://localhost:${port}/demo.web.html\n`);
|
||||
} else {
|
||||
await esbuild.build(buildOptions);
|
||||
}
|
||||
Reference in New Issue
Block a user