-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
120 lines (105 loc) · 3.35 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
// Helpers
import { getComponentImports } from "./src/app/helpers/auto-imports.helper";
// Path
import path from "path";
// URL
import { fileURLToPath, URL } from "url";
// Unplugin libraries
/**
* @description Vite plugin to automatically import files from a directory.
* @see https://github.com/antfu/unplugin-auto-import
*/
import AutoImport from "unplugin-auto-import/vite";
/**
* @description Vite plugin to minify images using imagemin.
* @see https://github.com/unplugin/unplugin-imagemin
*/
import imagemin from "unplugin-imagemin/vite";
// Vite libraries
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc";
/**
* @description Vite plugin to minify svg files
* @see https://github.com/vbenjs/vite-plugin-svg-icons
*/
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
/**
* @description Vite plugin to remove console.log and other console.* calls from your code.
* @see https://github.com/xiaoxian521/vite-plugin-remove-console
*/
import removeConsole from "vite-plugin-remove-console";
/**
* @description Vite plugin to compress the build output using vite-plugin-compression.
* @see https://github.com/vbenjs/vite-plugin-compression
*/
import viteCompression from "vite-plugin-compression";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
AutoImport({
// Enable auto import by filename for default module exports under directories
defaultExportByFilename: false,
// Auto import for module exports under directories
// by default it only scan one level of modules under the directory
dirs: ["src/app/constants", "src/app/helpers"],
// Filepath to generate corresponding .d.ts file.
// Defaults to './auto-imports.d.ts' when `typescript` is installed locally.
// Set `false` to disable.
dts: "src/app/types/auto-imports.d.ts",
// Generate corresponding .eslintrc-auto-import.json file.
// eslint globals Docs - https://eslint.org/docs/user-guide/configuring/language-options#specifying-globals
eslintrc: {
enabled: true,
},
// global imports to register
imports: [
// @ts-expect-error - Add global imports here
...getComponentImports(),
// @ts-expect-error - Add global imports here
"react",
],
// Include auto-imported packages in Vite's `optimizeDeps` options
// Recommend to enable
viteOptimizeDeps: true,
}),
createSvgIconsPlugin({
// Specify the icon folder to be cached
iconDirs: [path.resolve(process.cwd(), "src/app/assets/icons")],
// Specify symbolId format
symbolId: "icon-[dir]-[name]",
}),
imagemin({
// Default mode sharp. support squoosh and sharp
mode: "squoosh",
beforeBundle: true,
// Default configuration options for compressing different pictures
compress: {
jpg: {
quality: 10,
},
jpeg: {
quality: 10,
},
png: {
quality: 10,
},
webp: {
quality: 10,
},
},
conversion: [
{ from: "jpeg", to: "webp" },
{ from: "png", to: "webp" },
{ from: "JPG", to: "jpeg" },
],
}),
react(),
removeConsole(),
viteCompression(),
],
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),
},
},
});