Add Bun plugin to stop hmr routes in development from crashing

This commit is contained in:
2026-04-16 01:52:27 -07:00
parent f6275e4f58
commit c29244d2b6
2 changed files with 31 additions and 1 deletions

View File

@@ -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;

View File

@@ -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"]