-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
115 lines (111 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
import vue from '@vitejs/plugin-vue';
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';
import { type PluginOption, defineConfig } from 'vite';
import externalGlobals from 'rollup-plugin-external-globals';
import Components from 'unplugin-vue-components/vite';
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
// import { splitVendorChunkPlugin } from "vite";
import vueJsx from '@vitejs/plugin-vue-jsx';
import path from 'path';
const ifInclude = (s: string, ...params: string[]) => {
for (let i of params) {
if (s.includes(i)) {
return true;
}
}
return false;
};
export default defineConfig({
plugins: [
vue(),
vueJsx(),
// splitVendorChunkPlugin(),
createSvgIconsPlugin({
// 图标文件夹为src/assets/icons
iconDirs: [path.resolve(process.cwd(), 'src/assets/svg')],
// 指定symbolId格式
symbolId: 'icon-[dir]-[name]'
}),
Components({
// dirs: ['src'],
// extensions: ['vue', 'tsx', 'jsx'],
// deep: true,
// dts: false,
// directives: true,
// include: [/.vue$/, /.vue?vue/],
// exclude: [/[\/]node_modules[\/]/, /[\/].git[\/]/, /[\/].nuxt[\/]/],
resolvers: [
AntDesignVueResolver({
importStyle: false // css in js
})
]
}),
{
name: 'console',
configResolved(config) {
console.log("🚀 Project is Running!! Power by Silan's Coding Skill");
}
}
],
resolve: {
alias: [
{
find: '@',
replacement: path.resolve(__dirname, './src')
},
{ find: '@pages', replacement: path.resolve(__dirname, './src/pages') }
]
},
build: {
minify: 'terser', // 使用 terser 插件来压缩构建输出
sourcemap: false, // 生产环境是否生成 source map
rollupOptions: {
external: ['echarts'],
plugins: [
externalGlobals({
echarts: 'echarts'
}) as any
],
output: {
manualChunks(id: string) {
// the most important information is here:
// 1.Automatically generate build bundles,and identify both small and large library&modules
// 2.declare the larger name,and the smaller one will be built into one bundle
if (ifInclude(id, 'node_modules')) {
const name = id.toString().split('node_modules/')[1];
if (ifInclude(name, 'vue', '@vue')) {
return '@vue';
}
if (ifInclude(name, 'ant-design-vue', '@ant-design')) {
return '@ant-design';
}
if (ifInclude(name, '@tinymce', 'tinymce')) {
return '@tinymce';
}
if (ifInclude(name, 'highlight.js')) {
return '@highlight.js';
}
return 'power-code';
}
// creating a chunk to react routes deps. Reducing the vendor chunk size
// if (id.includes("node_modules")) {
}
} // 在此处使用类型断言告诉 TypeScript,output 具有 chunkSizeWarningLimit 属性
},
commonjsOptions: {
transformMixedEsModules: true
}
},
server: {
host: '0.0.0.0',
port: 3000,
proxy: {
'/api/v1': {
changeOrigin: true,
secure: false,
target: 'http://localhost:2334',
rewrite: (path) => path.replace(/^\/api\/v1/, '/api/v1')
}
}
}
});