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

https://github.com/mini-ghost/vite-async-component-loader

Vite plugin that easiest way loads component files as asynchronous components.
https://github.com/mini-ghost/vite-async-component-loader

Last synced: 6 months ago
JSON representation

Vite plugin that easiest way loads component files as asynchronous components.

Awesome Lists containing this project

README

          

# vite-async-component-loader

[![NPM version](https://img.shields.io/npm/v/vite-async-component-loader?color=34A88C&label=)](https://www.npmjs.com/package/vite-async-component-loader)

Vite plugin that easiest way loads component files as asynchronous components.

## Usage

It will automatically turn this

```vue

import LazyComponent from './Component.vue?async'

```

into this

```vue

import { defineAsyncComponent } from 'vue'

const LazyComponent = defineAsyncComponent(() => import('./Component.vue'))

```

## Install

```bash
npm install -D vite-async-component-loader
```

## Setup

```ts
// vite.config.ts
import { defineConfig } from 'vite'
import Vue from '@vitejs/plugin-vue'
import AsyncComponentLoader from 'vite-async-component-loader'

export default defineConfig({
plugins: [
AsyncComponentLoader()
]
})
```

## Use with TypeScript

We provide a `vite-async-component-loader/client` type declaration file for TypeScript users. You can create an env.d.ts in the src directory so TypeScript picks up the type definitions:

```ts
///
```

## License

[MIT License](https://github.com/Mini-ghost/vite-async-component-loader/blob/main/LICENSE) © 2023-PRESENT [Alex Liu](https://github.com/Mini-ghost)