Skip to content

Commit 158b817

Browse files
author
kevin
committed
feat: add alias in the vite.config.js
1 parent 51ff745 commit 158b817

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1+
配置 `vue3`的基础的工程模板
2+
13
### 创建工程
24

5+
执行下面的命令创建工程,根据提示选择 `vue`
6+
7+
```
8+
npm init vite vue3-vite-js-template
9+
```
10+
311
```
412
npm install eslint eslint-plugin-vue @babel/core @babel/eslint-parser -D
513
```
@@ -155,6 +163,8 @@ npx --no-install lint-staged
155163
156164
```
157165

166+
### 创建别名
167+
158168
### router
159169

160170
安装 `vue-router`

src/router/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createRouter, createWebHashHistory } from 'vue-router'
2-
import Layout from '../layouts/Layout.vue'
2+
import Layout from '@layout/Layout.vue'
33
const routes = [
44
{
55
path: '/',
@@ -10,7 +10,7 @@ const routes = [
1010
{
1111
path: 'home',
1212
name: 'Home',
13-
component: () => import('../pages/Home.vue')
13+
component: () => import('@page/Home.vue')
1414
}
1515
]
1616
}

vite.config.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
import { defineConfig } from 'vite'
22
import vue from '@vitejs/plugin-vue'
3+
import path from 'path'
34

45
// https://vitejs.dev/config/
56
export default defineConfig({
6-
plugins: [vue()]
7+
plugins: [vue()],
8+
resolve: {
9+
alias: {
10+
'@': path.resolve(__dirname, 'src'),
11+
'@component': path.resolve(__dirname, 'src/components'),
12+
'@layout': path.resolve(__dirname, 'src/layouts'),
13+
'@page': path.resolve(__dirname, 'src/pages')
14+
}
15+
}
716
})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy