Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions esbuild.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,38 @@ const sharedConfig = {

async function build() {
try {
await esbuild.build({
const ctx1 = await esbuild.context({
...sharedConfig,
outfile: "dist/main.cjs.js",
format: "cjs"
})

await esbuild.build({
const ctx2 = await esbuild.context({
...sharedConfig,
outfile: "dist/main.es.js",
format: "esm"
})

const result = await esbuild.build({
const ctx3 = await esbuild.context({
...sharedConfig,
minifyWhitespace: true,
outfile: "dist/main.es.bundle.js",
format: "esm",
metafile: true
})

fs.writeFileSync("meta.json", JSON.stringify(result.metafile))
if (process.argv.includes("--watch")) {
await Promise.all([ctx1.watch(), ctx2.watch(), ctx3.watch()])
console.info("Watching for changes...")
} else {
const results = await Promise.all([ctx1.rebuild(), ctx2.rebuild(), ctx3.rebuild()])
fs.writeFileSync("meta.json", JSON.stringify(results[2].metafile))

console.log("Build completed successfully.")
ctx1.dispose()
ctx2.dispose()
ctx3.dispose()
console.info("Build completed successfully.")
}
} catch (error) {
console.error("Build failed:", error)
process.exit(1)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
},
"scripts": {
"build": "tsc --project tsconfig.types.json && node esbuild.mjs && npm run typedoc",
"dev": "node esbuild.mjs --watch & vite preview --outDir dist",
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ampersand operator (&) runs the esbuild process in the background, but this can cause issues with proper cleanup and signal handling. If the dev script is terminated, the background esbuild process may continue running. Consider using a tool like concurrently or npm-run-all to run both commands in parallel, or use the double ampersand (&&) if sequential execution is intended.

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The --outDir flag is not a valid option for vite preview command. The vite preview command serves the built output from the directory specified in the build.outDir config option (which defaults to 'dist'). This flag will be ignored by vite preview, making it misleading. Remove the --outDir dist argument from this command.

Suggested change
"dev": "node esbuild.mjs --watch & vite preview --outDir dist",
"dev": "node esbuild.mjs --watch & vite preview",

Copilot uses AI. Check for mistakes.
"preview": "vite preview",
"lint": "eslint",
"lint-fix": "eslint --fix",
Expand Down
5 changes: 5 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ export default defineConfig(() => ({
server: {
port: 8080
},
preview: {
port: 40510,
open: false,
cors: true
},
test: {
coverage: {
include: ["src/**/*.{js,ts}"],
Expand Down