1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- /*
- * @Author: zc
- * @Description:
- * @version:
- * @Date: 2022-08-09 16:19:58
- * @LastEditors: Please set LastEditors
- * @LastEditTime: 2022-09-22 14:41:02
- */
- import vue from '@vitejs/plugin-vue';
- import { resolve } from 'path';
- import { defineConfig, loadEnv, ConfigEnv } from 'vite';
- import vueSetupExtend from 'vite-plugin-vue-setup-extend'; // setup语法糖设置name
- const pathResolve = (dir: string): any => {
- return resolve(__dirname, '.', dir);
- };
- const alias: Record<string, string> = {
- '/@': pathResolve('./src/'),
- };
- const viteConfig = defineConfig((mode: ConfigEnv) => {
- const env = loadEnv(mode.mode, process.cwd());
- return {
- plugins: [
- vue(),
- vueSetupExtend()
- ],
- root: process.cwd(),
- resolve: { alias },
- base: mode.command === 'serve' ? './' : env.VITE_PUBLIC_PATH,
- server: {
- host: '0.0.0.0',
- port: env.VITE_PORT as unknown as number,
- open: false, // 是否打开浏览器
- proxy: {
- '/api': {
- target: 'http://192.168.100.22:50001/',
- ws: true,
- changeOrigin: true,
- rewrite: (path) => path.replace(/^\/api/, ''),
- },
- },
- },
- 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', 'pinia'],
- echarts: ['echarts'],
- },
- },
- },
- minify: 'terser',
- terserOptions: {
- //生产环境时移除console
- compress: {
- drop_console: false,
- drop_debugger: true
- }
- }
- },
- css: { preprocessorOptions: { css: { charset: false } } },
- };
- });
- export default viteConfig;
|