Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/stolinski/auto-import-lib-bug


https://github.com/stolinski/auto-import-lib-bug

Last synced: 27 days ago
JSON representation

Awesome Lists containing this project

README

        

# vite-plugin-autoimport

Automatically detect and import components/modules for SvelteKit projects.

### Before

Code without vite-plugin-autoimport

### After

Code with vite-plugin-autoimport

## Installation

```bash
npm i -D vite-plugin-autoimport
```

## Basic configuration

```js
// svelte.config.js

import autoImport from 'vite-plugin-autoimport';

export default {
kit: {
vite: {
plugins: [
autoImport({
components: ['./src/components'],
})
]
}
}
}
```

## Name strategy

By default the component names will be **namespaced** with its directory names and
normalized to **upper camel case**. For example:

```html

```

## Prefix

All components can be prefixed with a given name.

```js
autoImport({
components: [{ name: './src/components', prefix: 'shared' } ],
})
```

So that

```html

```

## Flat

If the `flat` option is set to be true, no namespace will be added.

```js
autoImport({
components: [{ name: './src/components', flat: true } ],
})
```

So that

```html

```

## Full options

```js
// svelte.config.js
import autoImport from 'vite-plugin-autoimport';

export default {
kit: {
vite: {
plugins: [
autoImport({

// where to search for the components
components: [
'./src/components',
'./src/routes/_fragments',
{ name: './src/lib', flat: true, prefix: 'lib' },
],

// some frequently used modules
module: {
svelte: ['onMount', 'createEventDispatcher']
},

// manually import
mapping: {
API: `import API from '~/src/api'`,
Icon: `import * as Icon from '$components/icon'`,
},

// autoimport only for .svelte files
// and only search for .svelte files inside components
include: ['**/*.svelte'],

// node_modules is ignored by default
exclude: ['**/node_modules/**'],

})
]
}
}
}
```