-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
145 lines (136 loc) · 4.17 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import unocss from 'unocss/vite';
import AutoImport from 'unplugin-auto-import/vite';
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';
import Components from 'unplugin-vue-components/vite';
import { fileURLToPath, URL } from 'url';
import { defineConfig, loadEnv } from 'vite';
import { nodePolyfills } from 'vite-plugin-node-polyfills';
import vitePluginRequireTransform from 'vite-plugin-require-transform';
import Pages from 'vite-plugin-pages';
import svgLoader from 'vite-svg-loader';
import basicSsl from '@vitejs/plugin-basic-ssl';
import vue from '@vitejs/plugin-vue';
import topLevelAwait from 'vite-plugin-top-level-await';
import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill';
import { NodeModulesPolyfillPlugin } from '@esbuild-plugins/node-modules-polyfill';
import rollupNodePolyFill from 'rollup-plugin-node-polyfills';
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd());
const processEnvValues = {
'process.env': Object.entries(env).reduce((prev, [key, val]) => {
return {
...prev,
[key]: val,
};
}, {}),
};
return {
plugins: [
vue(),
Pages(),
svgLoader(),
basicSsl(),
unocss(),
topLevelAwait(),
vitePluginRequireTransform({
fileRegex: /.ts$|.vue$/,
}),
Components({
dirs: ['src/components'],
extensions: ['vue'],
dts: 'src/components.d.ts',
deep: true,
resolvers: [
AntDesignVueResolver({
importStyle: true,
}),
],
}),
AutoImport({
imports: ['vue', 'vue-router', '@vueuse/core'],
dts: 'src/auto-imports.d.ts',
resolvers: [AntDesignVueResolver()],
}),
nodePolyfills({
// To add only specific polyfills, add them here. If no option is passed, adds all polyfills
include: ['path'],
// To exclude specific polyfills, add them to this list. Note: if include is provided, this has no effect
exclude: [
'http', // Excludes the polyfill for `http` and `node:http`.
],
// Whether to polyfill specific globals.
globals: {
Buffer: true, // can also be 'build', 'dev', or false
global: true,
process: true,
},
// Override the default polyfills for specific modules.
overrides: {
// Since `fs` is not supported in browsers, we can use the `memfs` package to polyfill it.
fs: 'memfs',
},
// Whether to polyfill `node:` protocol imports.
protocolImports: true,
}),
],
css: {
preprocessorOptions: {
less: {
javascriptEnabled: true,
},
},
},
server: {
host: '0.0.0.0',
port: 9900,
https: true,
},
define: Object.assign(processEnvValues, {}),
resolve: {
// alias: [{ find: '@', replacement: fileURLToPath(new URL('./src', import.meta.url)) }],
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
stream: 'vite-compatible-readable-stream',
},
},
build: {
target: ['es2020'],
rollupOptions: {
plugins: [rollupNodePolyFill({})],
output: {
manualChunks: {
pinia: ['pinia'],
vue: ['vue', 'vue-router'],
'@fortawesome': [
'@fortawesome/fontawesome-svg-core',
'@fortawesome/free-brands-svg-icons',
'@fortawesome/free-regular-svg-icons',
'@fortawesome/free-solid-svg-icons',
'@fortawesome/vue-fontawesome',
],
'@ant-design': ['ant-design-vue'],
'@vueuse': ['@vueuse/core'],
'lodash-es': ['lodash-es'],
},
},
},
},
optimizeDeps: {
esbuildOptions: {
target: 'es2020',
define: {
global: 'globalThis',
},
// Enable esbuild polyfill plugins
plugins: [
NodeGlobalsPolyfillPlugin({
process: true,
buffer: true,
}),
NodeModulesPolyfillPlugin(),
],
},
},
};
});