-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
61 lines (59 loc) · 1.59 KB
/
vite.config.ts
File metadata and controls
61 lines (59 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import path from 'path';
import UnoCSS from 'unocss/vite';
//自动导入路由
import Pages from 'vite-plugin-pages';
// import generouted from '@generouted/react-router/plugin';
// https://vite.dev/config/
export default defineConfig({
plugins: [
react(),
UnoCSS(),
// generouted(),
Pages({
// 只对前台页面启用自动路由
dirs: [
{
dir: 'src/pages',
baseRoute: '/',
},
],
// extendRoute(route) {
// console.log(route.path);
// if (route.path === '/') {
// return {
// ...route,
// element: `() => {
// const { Navigate } = require('react-router-dom')
// return React.createElement(Navigate, { to: '/post/1', replace: true })
// }`,
// };
// }
// return route;
// },
extensions: ['tsx', 'jsx'],
// 排除后台相关文件
exclude: ['**/admin/**', '**/components/**'],
// 自定义路由生成
onRoutesGenerated: (routes) => {
// 可以在这里对自动生成的路由进行处理
console.log('Generated routes:', routes);
return routes;
},
}),
],
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
},
},
css: {
preprocessorOptions: {
scss: {
// 自动导入全局SCSS变量
additionalData: `@import "@/assets/styles/variables.scss";`,
},
},
},
});