Handle static assets as files in esbuild

This commit is contained in:
Alex Gleason committed 2025-10-05 15:04:15 -05:00
1 parent 275d8691cb
commit a05b5e8610
2 files changed
+10 -4

No files matched your search

+4 -2
View File
@@ -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,
+6 -2
View File
@@ -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 {