一、创建Vite+TS
1、安装 npm init @vitejs/app

2、选择框架


3、安装依赖 npm install(npm i)
vite官网
typescript官网
二、Vue-Router
1、安装:npm i vue-router@next
2、 新建router->index.ts
文件

3、写入
import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
const routes: Array<RouteRecordRaw> = [
{路由规则}
]
const router = createRouter({
history: createWebHashHistory(),
routes,
});
export default router
4、在mian.ts文件中引入

Vue-Router官网
三、Vuex
1、安装 npm install vuex@next --save
2、新建store->index.ts

3、写入
import { createStore } from "vuex";
export default createStore({
state: {},
mutations: {},
actions: {},
modules: {},
});
4、在main中引入

Vuex官网
四、Sass
1、安装 npm install --save-dev sass
就这么一句安装就可以使用了,用vuecli的时候,还要安装sass-loader、node-sass等,但是vite只需要安装sass就可以了
2、测试


3、如果需要全局使用sass变量,在vite.config.js文件中新增
css:{
preprocessorOptions: {
scss: {
/* .scss全局预定义变量,引入多个文件 以;(分号分割)*/
additionalData: `@import "./src/styles/css/global.scss";`,
},
},
},
五、其他配置 vite.config.js
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from "path";
// https://vitejs.dev/config/
export default defineConfig({
// 插件配置
plugins: [vue()],
//设置的别名
resolve: {
// 如果报错__dirname找不到,需要安装node,
// 执行npm i @types/node --save-dev
alias: {
'@': path.resolve(__dirname, "./src"),
"@assets": path.resolve(__dirname, "./src/assets"),
"@common": path.resolve(__dirname, "./src/common"),
"@utils": path.resolve(__dirname, "./src/utils"),
"@components": path.resolve(__dirname, "./src/components"),
"@views": path.resolve(__dirname, "./src/views"),
"@styles": path.resolve(__dirname, "./src/styles"),
},
},
// 服务配置
server:{
port:3000,// 端口号
open:true,// 自动在浏览器打开
https:false,// 是否开启 https
},
// css 处理
css:{
preprocessorOptions: {
scss: {
/* .scss全局预定义变量,引入多个文件 以;(分号分割)*/
additionalData: `@import "./src/styles/css/global.scss";`,
},
},
},
// 生产环境
build: {
//指定输出路径
assetsDir: "./",
// 指定输出文件路径
outDir: "dist",
// 代码压缩配置
terserOptions: {
// 生产环境移除console
compress: {
drop_console: true,
drop_debugger: true,
},
},
},
});
六、Ant-Desgin-Vue
官网
1、安装 npm install ant-design-vue@next --save
2、引入
import AntD from "ant-design-vue";
import "ant-design-vue/dist/antd.css";

网友评论