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
| import vue from '@vitejs/plugin-vue';
| import autoprefixer from 'autoprefixer';
| import { CodeInspectorPlugin } from 'code-inspector-plugin';
| import { resolve } from 'path';
| import tailwindcss from 'tailwindcss';
| import type { ConfigEnv } from 'vite';
| import { defineConfig, loadEnv } from 'vite';
| // import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
| // import AutoImport from 'unplugin-auto-import/vite';
| // import Components from 'unplugin-vue-components/vite';
| import viteCompression from 'vite-plugin-compression';
| import vueSetupExtend from 'vite-plugin-vue-setup-extend-plus';
| const pathResolve = (dir: string) => {
| return resolve(__dirname, '.', dir);
| };
|
| const alias: Record<string, string> = {
| '/@': pathResolve('./src/'),
| 'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js',
| };
|
| const viteConfig = defineConfig((mode: ConfigEnv) => {
| const env = loadEnv(mode.mode, process.cwd());
| return {
| plugins: [
| CodeInspectorPlugin({
| bundler: 'vite',
| hotKeys: ['shiftKey'],
| }),
| vue(),
| vueSetupExtend(),
| viteCompression({
| threshold: 1024000,
| }),
| // AutoImport({
| // resolvers: [ElementPlusResolver()],
| // }),
| // Components({
| // resolvers: [ElementPlusResolver()],
| // }),
| // rollup-plugin-visualizer 打包分析,开启后,npm run build 自动打开打包后的模块图
| // visualizer({
| // gzipSize: true,
| // brotliSize: true,
| // emitFile: false,
| // filename: 'stats.html', //分析图生成的文件名
| // open: true, //如果存在本地服务端口,将在打包后自动展示
| // }),
| ],
| root: process.cwd(),
| resolve: { alias },
| base: mode.command === 'serve' ? './' : env.VITE_PUBLIC_PATH,
| optimizeDeps: {
| include: ['element-plus/lib/locale/lang/zh-cn', 'element-plus/lib/locale/lang/en', 'element-plus/lib/locale/lang/zh-tw'],
| },
| server: {
| host: '0.0.0.0',
| port: env.VITE_PORT as unknown as number,
| open: JSON.parse(env.VITE_OPEN),
| hmr: true,
| proxy: {
| '/events': {
| target: 'http://localhost:3000',
| changeOrigin: true,
| },
| /** @description 百度语音识别 */
| '/api/baidu/speech_recognition': {
| target: 'https://aip.baidubce.com/rpc/2.0/tts/v1',
| changeOrigin: true,
| },
| /** @description 百度语音合成 */
| '/api/baidu/speech_synthesis': {
| target: 'https://aip.baidubce.com/rpc/2.0/tts/v1',
| changeOrigin: true,
| rewrite: (path) => {
| const newPath = path.replace('/api/baidu/speech_synthesis', '');
| return newPath;
| },
| },
| },
| },
| build: {
| outDir:'dist',
| chunkSizeWarningLimit: 1500,
|
| rollupOptions: {
| output: {
| entryFileNames: `assets/[name].[hash].js`,
| chunkFileNames: `assets/[name].[hash].js`,
| assetFileNames: `assets/[name].[hash].[ext]`,
| compact: true,
| // manualChunks: {
| // vue: ['vue', 'vue-router', 'pinia'],
| // echarts: ['echarts'],
| // },
| manualChunks(id) {
| if (id.includes('node_modules')) {
| return id.toString().split('node_modules/')[1].split('/')[0].toString();
| }
| },
| },
| },
| },
| css: {
| preprocessorOptions: { css: { charset: false } },
|
| postcss: {
| plugins: [tailwindcss, autoprefixer],
| },
| },
| define: {
| __VUE_I18N_LEGACY_API__: JSON.stringify(false),
| __VUE_I18N_FULL_INSTALL__: JSON.stringify(false),
| __INTLIFY_PROD_DEVTOOLS__: JSON.stringify(false),
| __NEXT_VERSION__: JSON.stringify(process.env.npm_package_version),
| __NEXT_NAME__: JSON.stringify(process.env.npm_package_name),
| },
| };
| });
|
| export default viteConfig;
|
|