---
title: "@farmfe/plugin-auto-import"
locale: "en"
version: "current"
canonicalUrl: "https://farmfe.org/docs/plugins/official-plugins/auto-import"
publicationStatus: "prerelease"
---

<a id="farmfeplugin-auto-import"></a>
# @farmfe/plugin-auto-import


Rust plugin that injects imports for matched identifiers from presets and scanned local exports.


<a id="installation"></a>
## Installation


**npm**

```javascript
npm install @farmfe/plugin-auto-import
```


**yarn**

```javascript
yarn add @farmfe/plugin-auto-import
```


**pnpm**

```javascript
pnpm add @farmfe/plugin-auto-import
```



<a id="usage"></a>
## Usage


```ts
import { defineConfig } from "@farmfe/core";
import autoImport from "@farmfe/plugin-auto-import";
import react from "@farmfe/plugin-react";

export default defineConfig({
  plugins: [
    react({ runtime: "automatic" }),
    autoImport({
      presets: ["react", "react-router-dom"],
      dirs: ["src/apis"],
      dts: "src/auto-imports.d.ts",
    }),
  ],
});
```


Supported string presets are ` react `, ` react-router `, ` react-router-dom `, ` vue `, ` vue-router `, and ` pinia `.


<a id="options"></a>
## Options


- ` dirs?: string[] ` — directories to scan for exports. Defaults to no extra directories.
- ` dts?: boolean | string ` — generate an auto-import declaration file. Defaults to ` true `; pass a string to choose the file path.
- ` ignore?: string[] ` — regular expression strings for import names to ignore.
- ` presets?: Array<string | { from: string; imports: string[] } | Record<string, Array<string | [string, string]>>> ` — built-in or custom imports. Tuple entries alias an import name.
- ` include?: string[] ` — regular expression strings for module ids to transform.
- ` exclude?: string[] ` — regular expression strings for module ids to skip. Defaults to ` ["node_modules"] `.
- ` injectAtEnd?: boolean ` — inject generated imports at the end of the module. Defaults to ` false `.
