From c29244d2b60d8b93f7ad16f0cb3678e77eab0ba2 Mon Sep 17 00:00:00 2001 From: Caleb Braaten Date: Thu, 16 Apr 2026 01:52:27 -0700 Subject: [PATCH] Add Bun plugin to stop hmr routes in development from crashing --- bun_plugins/onRuntime-external-urls.ts | 30 ++++++++++++++++++++++++++ bunfig.toml | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 bun_plugins/onRuntime-external-urls.ts diff --git a/bun_plugins/onRuntime-external-urls.ts b/bun_plugins/onRuntime-external-urls.ts new file mode 100644 index 0000000..c5f5765 --- /dev/null +++ b/bun_plugins/onRuntime-external-urls.ts @@ -0,0 +1,30 @@ +import type { BunPlugin } from 'bun'; + +/** + * Plugin to prevent Bun's bundler from analyzing certain URL patterns. + * Marks URLs that should remain as runtime URLs as external. + */ +const runtimeExternalUrlsPlugin: BunPlugin = { + name: 'runtime-external-urls', + setup(build) { + // Intercept resolution of paths that start with / + build.onResolve({ filter: /^\// }, args => { + // Mark specific runtime URLs as external to prevent bundler analysis + const externalPatterns = [ + '/profile-picture.webp', + // Add other runtime URLs here as needed + ]; + + if (externalPatterns.some(pattern => args.path.includes(pattern))) { + return { + path: args.path, + external: true, // This tells the bundler NOT to bundle this + }; + } + + return undefined; // Let normal resolution continue + }); + }, +}; + +export default runtimeExternalUrlsPlugin; diff --git a/bunfig.toml b/bunfig.toml index 918aa15..3857786 100644 --- a/bunfig.toml +++ b/bunfig.toml @@ -1,4 +1,4 @@ preload = ["./bun_plugins/onStartup-post-importer.ts"] [serve.static] -plugins = ["./bun_plugins/onImport-markdown-loader.tsx"] +plugins = ["./bun_plugins/onImport-markdown-loader.tsx", "./bun_plugins/onRuntime-external-urls.ts"]