mirror of
https://github.com/oven-sh/bun
synced 2026-02-11 11:29:02 +00:00
Fixes #3894 Previously, runtime plugins (using `plugin()` API) only received `path` in their onLoad callbacks, making them much less capable than Bun.build() plugins which receive `path`, `namespace`, and `loader`. This change adds: - **namespace** property - allows plugins to distinguish between different virtual module namespaces - **loader** property - provides default loader based on file extension (js, tsx, jsx, json, text, toml, file) This enables better plugin composition and makes it possible to: - Pass information from onResolve to onLoad via namespace - Handle query strings in imports (workaround for missing pluginData) - Know the default loader for conditional handling Example usage: ```typescript plugin({ setup(builder) { builder.onResolve({ filter: /\.mdx/ }, (args) => { const [path, query] = args.path.split("?"); // Store query data externally since pluginData doesn't work yet queryMap.set(path, parseQuery(query)); return { path, namespace: "mdx-loader" }; }); builder.onLoad({ namespace: "mdx-loader" }, (args) => { // Can now access namespace and retrieve query data const query = queryMap.get(args.path); // ... handle MDX with query parameters }); } }); ``` **Still missing** (future work): - pluginData property (would require tracking through resolve/load pipeline) - suffix property (esbuild compatibility) - defer, side properties (build-specific) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>