Skip to content

Commit

Permalink
feat: use unimport as the engine (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed May 24, 2022
1 parent 2e8075a commit d018629
Show file tree
Hide file tree
Showing 20 changed files with 521 additions and 450 deletions.
48 changes: 27 additions & 21 deletions README.md
Expand Up @@ -102,16 +102,7 @@ module.exports = {
<details>
<summary>Nuxt</summary><br>

```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)
> You **don't need** this plugin for Nuxt, it's already builtin.
<br></details>

Expand Down Expand Up @@ -207,24 +198,35 @@ AutoImport({
},
],

// Auto import for all module exports under directories
dirs: [
// './hooks',
// './composables'
// ...
],

// Filepath to generate corresponding .d.ts file.
// Defaults to './auto-imports.d.ts' when `typescript` is installed locally.
// Set `false` to disable.
dts: './auto-imports.d.ts',

// Auto import inside Vue template
// see https://github.com/unjs/unimport/pull/15
vueTemplate: false,

// Custom resolvers, compatible with `unplugin-vue-components`
// see https://github.com/antfu/unplugin-auto-import/pull/23/
resolvers: [
/* ... */
],

// Generate corresponding .eslintrc-auto-import.json file.
// eslint globals Docs - https://eslint.org/docs/user-guide/configuring/language-options#specifying-globals
eslintrc: {
enabled: false, // Default `false`
filepath: './.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json`
globalsPropValue: true, // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
},

// custom resolvers
// see https://github.com/antfu/unplugin-auto-import/pull/23/
resolvers: [
/* ... */
],

// Filepath to generate corresponding .d.ts file.
// Defaults to './auto-imports.d.ts' when `typescript` is installed locally.
// Set `false` to disable.
dts: './auto-imports.d.ts',
})
```

Expand Down Expand Up @@ -265,6 +267,10 @@ In order to properly hint types for auto-imported APIs, make sure:

## FAQ

### Compare to [`unimport`](https://github.com/unjs/unimport)

From v0.8.0, `unplugin-auto-import` **uses** `unimport` underneath. `unimport` is designed to be a lower level tool (it also powered Nuxt's auto import). You can think `unplugin-auto-import` is a wrapper of it that provides more user-friendly config APIs and capability like resolvers. Development of new features will mostly happend in `unimport` from now.

### Compare to [`vue-global-api`](https://github.com/antfu/vue-global-api)

You can think of this plugin as a successor to `vue-global-api`, but offering much more flexibility and bindings with libraries other than Vue (e.g. React).
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -93,8 +93,8 @@
"@rollup/pluginutils": "^4.2.0",
"local-pkg": "^0.4.1",
"magic-string": "^0.26.1",
"resolve": "^1.22.0",
"unplugin": "^0.6.1"
"unplugin": "^0.6.1",
"unimport": "^0.2.3"
},
"devDependencies": {
"@antfu/eslint-config": "^0.20.2",
Expand Down
4 changes: 3 additions & 1 deletion playground/App.vue
@@ -1,6 +1,7 @@
<script lang="ts" setup>
import HelloWorld from './HelloWorld.vue'
ElMessage.warning('Test')
const foo = useFoo()
</script>

<script lang="ts">
Expand All @@ -16,8 +17,9 @@ export default defineComponent({

<template>
<HelloWorld msg="hi" />
<pre>{{ foo }}</pre>
<pre>{{ FOOBAR }}</pre>
<div v-loading="false">
123
<ElButton>Hello</ElButton>
</div>
</template>
5 changes: 5 additions & 0 deletions playground/composables/foo.ts
@@ -0,0 +1,5 @@
export function useFoo() {
return 'foo from ./composables/'
}

export const FOOBAR = 'auto import in Vue template'
8 changes: 7 additions & 1 deletion playground/vite.config.ts
Expand Up @@ -10,7 +10,13 @@ export default defineConfig({
Inspect(),
AutoImport({
imports: ['vue', '@vueuse/core'],
resolvers: [ElementPlusResolver()],
resolvers: [
ElementPlusResolver(),
],
dirs: [
'./composables',
],
vueTemplate: true,
}),
],
})
103 changes: 100 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d018629

Please sign in to comment.