2021-03-15 12:44:58 +08:00
|
|
|
import vue from '@vitejs/plugin-vue';
|
2021-04-01 11:13:38 +08:00
|
|
|
import { resolve } from 'path';
|
2022-02-21 23:52:59 +08:00
|
|
|
import type { UserConfig, ConfigEnv } from 'vite';
|
|
|
|
import { defineConfig } from 'vite';
|
2021-06-19 17:49:42 +08:00
|
|
|
import { loadEnv } from './src/utils/viteBuild';
|
2020-12-21 00:14:57 +08:00
|
|
|
|
2021-04-01 11:13:38 +08:00
|
|
|
const pathResolve = (dir: string): any => {
|
|
|
|
return resolve(__dirname, '.', dir);
|
|
|
|
};
|
|
|
|
|
2021-03-15 12:44:58 +08:00
|
|
|
const { VITE_PORT, VITE_OPEN, VITE_PUBLIC_PATH } = loadEnv();
|
2020-12-21 00:14:57 +08:00
|
|
|
|
2021-04-01 11:13:38 +08:00
|
|
|
const alias: Record<string, string> = {
|
2021-08-20 18:58:52 +08:00
|
|
|
'/@': pathResolve('./src/'),
|
2021-04-01 11:13:38 +08:00
|
|
|
'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js',
|
|
|
|
};
|
|
|
|
|
2022-02-21 23:52:59 +08:00
|
|
|
export default defineConfig(({ command }: ConfigEnv): UserConfig => {
|
|
|
|
return {
|
|
|
|
plugins: [vue()],
|
|
|
|
root: process.cwd(),
|
|
|
|
resolve: { alias },
|
|
|
|
base: command === 'build' ? 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: VITE_PORT,
|
|
|
|
open: VITE_OPEN,
|
|
|
|
proxy: {
|
|
|
|
'/gitee': {
|
|
|
|
target: 'https://gitee.com',
|
|
|
|
ws: true,
|
|
|
|
changeOrigin: true,
|
|
|
|
rewrite: (path) => path.replace(/^\/gitee/, ''),
|
|
|
|
},
|
2021-03-15 12:44:58 +08:00
|
|
|
},
|
|
|
|
},
|
2022-02-21 23:52:59 +08:00
|
|
|
build: {
|
|
|
|
outDir: 'dist',
|
|
|
|
sourcemap: false,
|
|
|
|
chunkSizeWarningLimit: 1500,
|
|
|
|
rollupOptions: {
|
|
|
|
output: {
|
|
|
|
entryFileNames: `assets/[name].${new Date().getTime()}.js`,
|
|
|
|
chunkFileNames: `assets/[name].${new Date().getTime()}.js`,
|
|
|
|
assetFileNames: `assets/[name].${new Date().getTime()}.[ext]`,
|
|
|
|
compact: true,
|
|
|
|
manualChunks: {
|
|
|
|
vue: ['vue', 'vue-router', 'vuex'],
|
|
|
|
echarts: ['echarts'],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
terserOptions: {
|
|
|
|
compress: {
|
|
|
|
drop_console: true,
|
|
|
|
drop_debugger: true,
|
|
|
|
},
|
|
|
|
ie8: true,
|
|
|
|
output: {
|
|
|
|
comments: true,
|
|
|
|
},
|
2021-12-21 21:32:26 +08:00
|
|
|
},
|
|
|
|
},
|
2022-02-21 23:52:59 +08:00
|
|
|
css: {
|
|
|
|
postcss: {
|
|
|
|
plugins: [
|
|
|
|
{
|
|
|
|
postcssPlugin: 'internal:charset-removal',
|
|
|
|
AtRule: {
|
|
|
|
charset: (atRule) => {
|
|
|
|
if (atRule.name === 'charset') {
|
|
|
|
atRule.remove();
|
|
|
|
}
|
|
|
|
},
|
2021-12-22 21:37:33 +08:00
|
|
|
},
|
|
|
|
},
|
2022-02-21 23:52:59 +08:00
|
|
|
],
|
|
|
|
},
|
2021-12-22 21:37:33 +08:00
|
|
|
},
|
2022-02-21 23:52:59 +08:00
|
|
|
define: {
|
|
|
|
__VUE_I18N_LEGACY_API__: JSON.stringify(false),
|
|
|
|
__VUE_I18N_FULL_INSTALL__: JSON.stringify(false),
|
|
|
|
__INTLIFY_PROD_DEVTOOLS__: JSON.stringify(false),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|