From a05b5e861000a84c8d36676402561579d76d46f4 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 5 Oct 2025 14:52:16 -0500 Subject: [PATCH] Handle static assets as files in esbuild --- src/lib/build/esmPlugin.ts | 6 ++++-- src/lib/build/fsPlugin.ts | 8 ++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/lib/build/esmPlugin.ts b/src/lib/build/esmPlugin.ts index eb509116..ce5c61cc 100644 --- a/src/lib/build/esmPlugin.ts +++ b/src/lib/build/esmPlugin.ts @@ -1,3 +1,4 @@ +import { extname } from "path-browserify"; import type { Loader, Plugin } from "esbuild-wasm"; interface PackageLock { @@ -334,8 +335,9 @@ export function esmPlugin(packageLock: PackageLock, target?: string): Plugin { // ignore } - // Skip static assets - if (/\.(woff2?|ttf|otf|eot)$/.test(fullURL.pathname)) { + // Externalize static assets + const ext = extname(fullURL.pathname).slice(1); + if (ext && !["ts", "tsx", "js", "jsx", "mjs", "cjs", "css", "json"].includes(ext)) { return { path: fullURL.toString(), external: true, diff --git a/src/lib/build/fsPlugin.ts b/src/lib/build/fsPlugin.ts index 1352e274..a6abf2ea 100644 --- a/src/lib/build/fsPlugin.ts +++ b/src/lib/build/fsPlugin.ts @@ -71,8 +71,12 @@ export function fsPlugin(fs: JSRuntimeFS, cwd: string): Plugin { const ext = extname(path).slice(1); - if (!["ts", "tsx", "js", "jsx", "css", "json"].includes(ext)) { - return; + // Handle static assets + if (!["ts", "tsx", "js", "jsx", "mjs", "cjs", "css", "json"].includes(ext)) { + return { + contents: await fs.readFile(path), + loader: "file", + }; } return {