# unplugin-auto-import
**Repository Path**: chenming142/unplugin-auto-import
## Basic Information
- **Project Name**: unplugin-auto-import
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: MIT
- **Default Branch**: feat/auto-register-global-types
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2023-11-24
- **Last Updated**: 2023-11-24
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# unplugin-auto-import
[](https://www.npmjs.com/package/unplugin-auto-import)
Auto import APIs on-demand for Vite, Webpack and Rollup. With TypeScript support. Powered by [unplugin](https://github.com/unjs/unplugin).
---
without
```ts
import { ref, computed } from 'vue'
const count = ref(0)
const doubled = computed(() => count.value * 2)
```
with
```ts
const count = ref(0)
const doubled = computed(() => count.value * 2)
```
---
without
```tsx
import { useState } from 'react'
export function Counter() {
const [count, setCount] = useState(0)
return
{ count }
}
```
with
```tsx
export function Counter() {
const [count, setCount] = useState(0)
return { count }
}
```
## Install
```bash
npm i -D unplugin-auto-import
```
Vite
```ts
// vite.config.ts
import AutoImport from 'unplugin-auto-import/vite'
export default defineConfig({
plugins: [
AutoImport({ /* options */ }),
],
})
```
Example: [`playground/`](./playground/)
Rollup
```ts
// rollup.config.js
import AutoImport from 'unplugin-auto-import/rollup'
export default {
plugins: [
AutoImport({ /* options */ }),
// other plugins
],
}
```
Webpack
```ts
// webpack.config.js
module.exports = {
/* ... */
plugins: [
require('unplugin-auto-import/webpack')({ /* options */ })
]
}
```
Nuxt
```ts
// nuxt.config.js
export default {
buildModules: [
['unplugin-auto-import/nuxt', { /* options */ }],
],
}
```
> This module works for both Nuxt 2 and [Nuxt Vite](https://github.com/nuxt/vite)
Vue CLI
```ts
// vue.config.js
module.exports = {
configureWebpack: {
plugins: [
require('unplugin-auto-import/webpack')({ /* options */ }),
],
},
}
```
## Configuration
```ts
AutoImport({
// targets to transform
include: [
/\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
/\.vue$/, /\.vue\?vue/, // .vue
/\.md$/, // .md
],
// global imports to register
imports: [
// presets
'vue',
'vue-router',
// custom
{
'@vueuse/core': [
// named imports
'useMouse', // import { useMouse } from '@vueuse/core',
// alias
['useFetch', 'useMyFetch'] // import { useFetch as useMyFetch } from '@vueuse/core',
],
'axios': [
// default imports
['default', 'axios'] // import { default as axios } from 'axios',
],
'[package-name]': [
'[import-names]',
// alias
['[from]', '[alias]']
]
}
],
// custom resolvers
// see https://github.com/antfu/unplugin-auto-import/pull/23/
resolvers: [
/* ... */
]
})
```
Refer to the [type definitions](./src/types.ts) for more options.
## Presets
See [src/presets](./src/presets).
## FAQ
### Compare to [`vue-global-api`](https://github.com/antfu/vue-global-api)
You can think this plugin as a successor of `vue-global-api`, which offers much more flexibility and it's no longer bound to Vue exclusively. Now you can use it with any libraries you want (e.g. React).
###### Pros
- Flexible and customizable
- Tree-shakable (on-demand transforming)
- No global population
###### Cons
- Relying on build tools integrations (while `vue-global-api` is pure runtime) - but hey, we have supported quite a few of them already!
## Sponsors
## License
[MIT](./LICENSE) License © 2021 [Anthony Fu](https://github.com/antfu)