bun-plugin-auto-imports is a utility plugin designed for the Bun bundler, enabling automatic import resolution and injection into JavaScript and TypeScript files during the build process. It streamlines development by reducing the need for explicit import statements, similar to features found in other build tools like Vite or Webpack's auto-imports plugins. The package is currently at version 0.4.0, indicating it is still in active development, with frequent minor releases and bug fixes as seen in recent changelogs. Its primary differentiator is its native integration with the Bun ecosystem, offering potentially faster build times compared to non-Bun specific solutions. It supports features like specifying directories for auto-import detection and ESLint integration. This plugin is crucial for projects leveraging Bun that seek to enhance developer experience and reduce boilerplate code.
npm install bun-plugin-auto-importsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to configure `bun-plugin-auto-imports` in your Bun environment, specifying directories to scan, explicit imports, and generating TypeScript declaration files. It shows the plugin registration using `plugin()` and an example of its options.
Pin the package version in `package.json` (e.g., `"bun-plugin-auto-imports": "0.4.0"`) and thoroughly test updates.
Use specific `dirs` configurations, and explicitly define `imports` where clarity is needed. Leverage the generated `d.ts` file for type hinting to understand available globals.
Ensure you are on `v0.3.1` or newer. Test path configurations thoroughly, especially when deploying to different environments. Use absolute paths where ambiguity is a concern.
Regularly check the Bun and plugin repositories for updates and known issues. Report any new compatibility problems encountered.
Verify that the file containing the desired symbol is within one of the `dirs` specified in the plugin options. Ensure the symbol is a valid export (e.g., `export function myFunction() {}`). Consider adding it to the `imports` option explicitly if it's a third-party package.Explicitly define the import in the `imports` option of the plugin, specifying the exact named export. Ensure the source package's `package.json` correctly defines its `exports` field for proper module resolution.
Ensure you are using `import { autoImports } from 'bun-plugin-auto-imports';` and passing its result directly to `plugin()` or the `plugins` array in `Bun.build()`. Verify the options object conforms to `AutoImportsOptions`.Refactor your code to avoid naming conflicts. Use the `exclude` option in `AutoImportsOptions` (if available in this plugin, it's common in `unimport`-based plugins) to prevent specific symbols from being auto-imported, or prefix your auto-imported symbols to ensure uniqueness.
No dependency data recorded yet.