Extend Bun's module resolution and loading behavior
Plugins are applied in the order they are defined.
Today, there are two kinds of hooks:
onLoad
lets you return source code or an object that will become the module's exportsonResolve
lets you redirect a module specifier to another module specifier. It does not chain.
Plugin hooks must define a filter
RegExp and will only be matched if the import specifier contains a "." or a ":".
ES Module resolution semantics mean that plugins may be initialized after a module is resolved. You might need to load plugins at the very beginning of the application and then use a dynamic import to load the rest of the application. A future version of Bun may also support specifying plugins via bunfig.toml
.