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