-
Notifications
You must be signed in to change notification settings - Fork 2
/
vite.config.ts
124 lines (116 loc) · 3.23 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
124
import checker from "vite-plugin-checker";
import vue from "@vitejs/plugin-vue";
import { defineConfig, loadEnv } from "vite";
import { visualizer } from "rollup-plugin-visualizer";
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
import reactIcons from "vite-plugin-react-icons";
/**
* @description Enable import if you need polyfills
*
* import { nodePolyfills } from 'vite-plugin-node-polyfills'
* import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill'
* import { NodeModulesPolyfillPlugin } from '@esbuild-plugins/node-modules-polyfill'
*/
import * as fs from "fs";
import * as path from "path";
const appDirectory = fs.realpathSync(process.cwd());
const resolveApp = (relative: string) => path.resolve(appDirectory, relative);
const root = path.resolve(__dirname, resolveApp("src"));
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), "");
const isProduction = env.VITE_ENVIRONMENT === "production";
const isDevelopment = env.VITE_ENVIRONMENT === "development";
const isAnalyze = env.VITE_ENVIRONMENT === "analyze";
const buildVersion = env.VITE_BUILD_VERSION;
return {
...(env.VITE_PORT
? {
server: {
port: Number(env.VITE_PORT),
},
}
: {}),
publicDir: "static",
base: "",
build: {
rollupOptions: {
output: {
manualChunks: {
w3m: ["@web3modal/ethers5"],
chart: ["chart.js"],
},
},
},
},
plugins: [
vue(),
createSvgIconsPlugin({
iconDirs: [path.resolve(process.cwd(), "src/assets/icons")],
symbolId: "[name]",
}),
reactIcons(),
checker({
overlay: {
initialIsOpen: false,
},
typescript: true,
}),
...(isAnalyze
? [
visualizer({
open: true,
}),
]
: []),
],
css: {
preprocessorOptions: {
scss: {
additionalData: [
'@import "@/styles/_functions.scss";',
'@import "@/styles/_mixins.scss";',
].join(""),
},
},
},
resolve: {
extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue"],
dedupe: ["vue", "@vueuse/core", "lodash"],
alias: {
"@": `${root}/`,
"@config": `${root}/config.ts`,
"@static": `${root}/../static`,
},
},
/**
* @description Enable configuration for polyfills
*
* optimizeDeps: {
* esbuildOptions: {
* define: {
* global: 'globalThis',
* },
* },
* // Enable esbuild polyfill plugins
* plugins: [
* NodeGlobalsPolyfillPlugin({
* process: true,
* buffer: true,
* }),
* NodeModulesPolyfillPlugin(),
* ],
* },
* build: {
* target: 'esnext',
* rollupOptions: {
* plugins: [
* // Enable rollup polyfills plugin
* // used during production bundling
* nodePolyfills(),
* ],
* },
* },
*/
};
});