12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- 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,
- hmr: true,
- server: {
- host: '0.0.0.0',
- port: env.VITE_PORT as unknown as number,
- open: false, // 是否打开浏览器
- proxy: {
- '/api': {
- target: 'http://hotline.fw.com',
- ws: true,
- changeOrigin: true,
- rewrite: (path) => path.replace(/^\/api/, ''),
- },
- }
- },
- build: {
- outDir: 'dist',
- sourcemap: false,
- 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'],
- },
- },
- },
- minify: 'terser',
- terserOptions: {
- //生产环境时移除console
- compress: {
- drop_console: false,
- drop_debugger: true
- }
- }
- },
- css: { preprocessorOptions: { css: { charset: false } } },
- };
- });
- export default viteConfig;
|