Add Bun plugin to stop hmr routes in development from crashing
This commit is contained in:
30
bun_plugins/onRuntime-external-urls.ts
Normal file
30
bun_plugins/onRuntime-external-urls.ts
Normal 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;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
preload = ["./bun_plugins/onStartup-post-importer.ts"]
|
preload = ["./bun_plugins/onStartup-post-importer.ts"]
|
||||||
|
|
||||||
[serve.static]
|
[serve.static]
|
||||||
plugins = ["./bun_plugins/onImport-markdown-loader.tsx"]
|
plugins = ["./bun_plugins/onImport-markdown-loader.tsx", "./bun_plugins/onRuntime-external-urls.ts"]
|
||||||
|
|||||||
Reference in New Issue
Block a user