-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
123 lines (116 loc) · 3.34 KB
/
vite.config.ts
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import { fileURLToPath, URL } from 'node:url';
import react from '@vitejs/plugin-react';
import autoprefixer from 'autoprefixer';
import * as path from 'path';
import AutoImport from 'unplugin-auto-import/vite';
import { defineConfig, loadEnv } from 'vite';
import eslintPlugin from 'vite-plugin-eslint';
import mkcert from 'vite-plugin-mkcert';
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
import svgLoader from 'vite-svg-loader';
//@ts-ignore
import { dependencies } from './package.json';
function renderChunks(deps: Record<string, string>) {
const chunks = {};
Object.keys(deps).forEach((key) => {
if (['react', 'react-router-dom', 'react-dom'].includes(key)) return;
chunks[key] = [key];
});
return chunks;
}
export default ({ mode }) => {
// Load app-level env vars to node-level env vars.
process.env = { ...process.env, ...loadEnv(mode, process.cwd()) };
return defineConfig({
publicDir: 'public',
server: {
host: 'local.devgodbot.ru',
https: true,
port: 443,
proxy: {
'/api': {
target: process.env.VITE_API_PROXY,
changeOrigin: true,
// rewrite: (path) => path.replace(/^\/api/, ''),
// configure: (proxy, options) => {
// // proxy will be an instance of 'http-proxy'
// },
},
},
},
plugins: [
mkcert(),
AutoImport({
include: [
/\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
],
imports: [
'react',
'react-router-dom',
{
'react-i18next': ['useTranslation'],
classnames: [['default', 'cns']],
},
],
dirs: ['./src/core/**'],
dts: true,
eslintrc: {
enabled: true,
},
}),
react(),
eslintPlugin({
failOnError: false,
cache: false,
}),
createSvgIconsPlugin({
iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
symbolId: 'icon-[dir]-[name]',
}),
svgLoader(),
// visualizer({
// template: 'treemap', // or sunburst
// open: true,
// gzipSize: true,
// brotliSize: false,
// filename: 'bundle-analyze.html',
// }),
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
'@c': fileURLToPath(new URL('./src/components', import.meta.url)),
'@ui': fileURLToPath(new URL('./src/components/UI', import.meta.url)),
'@core': fileURLToPath(new URL('./src/core', import.meta.url)),
'@interface': fileURLToPath(new URL('./src/core/interface', import.meta.url)),
'@assets': fileURLToPath(new URL('./src/assets', import.meta.url)),
'@styles': fileURLToPath(new URL('./src/assets/styles', import.meta.url)),
},
},
build: {
outDir: 'build',
sourcemap: false,
rollupOptions: {
output: {
manualChunks: {
vendor: ['react', 'react-router-dom', 'react-dom'],
...renderChunks(dependencies),
},
},
},
},
css: {
postcss: {
// @ts-ignore
plugins: [autoprefixer()],
},
},
// css: {
// preprocessorOptions: {
// scss: {
// additionalData: `@import "@/assets/styles/utils/index.scss";`,
// },
// },
// },
});
};