Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/holy-two/vite-plugin-alias

alias from ts.config.json
https://github.com/holy-two/vite-plugin-alias

Last synced: 9 days ago
JSON representation

alias from ts.config.json

Awesome Lists containing this project

README

        

# @holy-two/vite-plugin-alias

![@holy-two/vite-plugin-alias](https://img.shields.io/npm/v/@holy-two/vite-plugin-alias.svg)

## Illustration

This is a vite plugin that automatically retrieves and sets path aliases from [`tsconfig.json`](./playground/tsconfig.json).

## Usage

```shell
npm i @holy-two/vite-plugin-alias -D
```

In `vite.config.ts`:

```diff
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
+ import vitePluginTemplate from '@holy-two/vite-plugin-alias'

export default defineConfig({
plugins: [vue(),
+ vitePluginTemplate(),
],
})

```

You just need to configure it like this in `tsconfig.json`:

```diff
{
"extends": "../tsconfig.json",
"compilerOptions": {
+ "baseUrl": ".",
+ "paths": {
+ "~/*": [
+ "src/*"
+ ]
+ }
},
"include": [
"src/**/*.vue",
"src/**/*.ts",
"vite.config.ts"
],
}
```

`@holy-two/vite-plugin-alias` will automatically parse the paths set within the paths to define aliases.
So you can use `~/components/**` (same as `./src/components/**`) to access files.