Skip to content

Commit

Permalink
Upgrade esbuilder to capture bundle metadata.
Browse files Browse the repository at this point in the history
  • Loading branch information
Cody Casterline committed Jun 26, 2023
1 parent 11ccea5 commit b241455
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 189 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
# Also ignore .sqlite3-shm and .sqlite3-wal, as well as any of your .sqlite3.backup files:
*.sqlite3*
/.vscode/

.DS_Store
1 change: 1 addition & 0 deletions web-client/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/node_modules/
/web_modules/
/build/
/esbuild.meta.json
24 changes: 19 additions & 5 deletions web-client/esbuilder.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import sveltePlugin from "esbuild-svelte";
import sveltePreprocess from "svelte-preprocess";
import copy from 'esbuild-copy-plugin';
import inlineWorkerPlugin from 'esbuild-plugin-inline-worker';

import { execSync } from "child_process";
import fs from "node:fs";

async function main() {

Expand All @@ -18,7 +17,7 @@ async function main() {


async function doEsBuild(opts = {}) {
let result = await esbuild.build({
let args = {
entryPoints: ['index.js'],
bundle: true,
outfile: 'build/index.js',
Expand All @@ -42,10 +41,25 @@ async function doEsBuild(opts = {}) {
format: "esm",
minify: true,
sourcemap: true,
metafile: true,

watch: opts.watch,
logLevel: opts.watch ? "debug" : "info",
}).catch(() => process.exit(1))
}

if (opts.watch) {
const ctx = await esbuild.context(args)
await ctx.watch()
console.log("watching:")
} else {
const result = await esbuild.build(args)
const json = JSON.stringify(result.metafile)
fs.writeFileSync("esbuild.meta.json", json)

// console.log(
// await esbuild.analyzeMetafile(result.metafile, {verbose: true})
// )
}

}

await main()
Loading

0 comments on commit b241455

Please sign in to comment.