/* * @Author: yufp * @Date: 2024-03-25 10:33:01 * @LastEditors: zhanglin3 * @LastEditTime: 2024-10-17 17:42:03 * @Description: 定义开发和构建的配置 */ import { resolve } from 'path'; import { defineConfig, loadEnv } from 'vite'; import vue2 from '@vitejs/plugin-vue2'; import vue2Jsx from '@vitejs/plugin-vue2-jsx'; import { viteExternalsPlugin } from 'vite-plugin-externals'; import mockDevServer from 'vite-plugin-mock-dev-server'; // 引入svg需要用到的插件, 安装 yarn add vite-plugin-svg-icons import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'; // 导入低码代理配置和忽略编译配置 import { watchOptionsIgnored } from '@yuxp/previewer/src/integration/server'; import createYuxpServerPlugin from '@yuxp/integration/yuxpServer/vite-plugin-yuxp-server'; import { getProxyConfig } from './build-proxy'; import insertYuxpProxy, { VITE_APP_YUXP_WATCH_IGNORED } from './src/config/yuxp/proxyConfig.js'; // 根据运行模式加载环境变量,并配置Vite export default ({ mode }) => { // 加载环境变量 const loadEnvVar = loadEnv(mode, process.cwd()); const { VITE_APP_DEV_PORT, VITE_APP_BASE_URL, VITE_APP_PROXY_API, VITE_APP_BASE_API, VITE_APP_BASE_AUTH, VITE_APP_PROXY_SHUFFLE, } = loadEnvVar; const proxy = getProxyConfig(loadEnvVar, insertYuxpProxy); const viteHost = '0.0.0.0'; // 返回Vite配置对象 return defineConfig({ define: { 'process.env': {}, }, base: VITE_APP_BASE_URL, // 设置项目基路径 plugins: [ vue2(), vue2Jsx(), // mockDevServer(), createSvgIconsPlugin({ // 配置svg图标 iconDirs: [ resolve(process.cwd(), 'src/style/svg'), resolve(process.cwd(), 'src/views/@xdjf/card/style/svg'), resolve(process.cwd(), 'src/views/@xdjf/intelligent-due-diligence/assets/icons/svg'), resolve(process.cwd(), 'src/views/@xdjf/intelligent-due-diligence/assets/icons/chatSvg'), resolve(process.cwd(), 'src/views/@xdjf/financial-analysis/assets/icons/svg'), ], symbolId: 'icon-[name]', }), // 低码yuxpServer服务插件 //createYuxpServerPlugin(), viteExternalsPlugin({ echarts: 'echarts', }), ], // 使用的插件 resolve: { alias: { package: resolve(__dirname, 'package.json'), 'yuxp-web': resolve('src'), assets: resolve(__dirname, 'src/assets'), static: resolve(__dirname, 'public/static'), '@': resolve(__dirname, 'src'), // 设置别名为src目录 '@xdjf/demo-web': resolve(__dirname, 'src/views/@xdjf/demo-web'), '@xdjf/card': resolve(__dirname, 'src/views/@xdjf/card'), '@xdjf/idd': resolve(__dirname, 'src/views/@xdjf/intelligent-due-diligence'), // 智能尽调 '@xdjf/fa': resolve(__dirname, 'src/views/@xdjf/financial-analysis'), // 财务分析 vue: resolve('node_modules/vue/dist/vue.esm.js'), '@yufp/store': resolve(__dirname, 'node_modules/@yufp/store/vuex/'), }, // 省略后缀 extensions: ['.vue', '.js', '.json', '.ts'], }, // scss全局变量的配置 css: { preprocessorOptions: { scss: { additionalData: '@import "./src/style/variables.scss";', }, }, }, optimizeDeps: { // 其他常用依赖 include: [ 'vue', 'echarts', 'vue-router', 'vuex', 'element-ui', 'axios', 'lodash', // shuffle 集成 'codemirror/addon/selection/active-line', 'codemirror/addon/hint/show-hint', 'codemirror/addon/edit/matchbrackets', 'codemirror/addon/edit/closebrackets', 'codemirror/mode/javascript/javascript', 'codemirror/mode/sql/sql', 'codemirror/lib/codemirror', ], esbuildOptions: { target: 'es2015', }, exclude: ['@ggzj/shuffle-lite-web'], }, server: { // 服务器配置 port: VITE_APP_DEV_PORT, // 设置开发服务器端口号 host: viteHost, // 监听所有网络接口 cors: true, // 启用跨域请求 proxy: proxy, // 使用定义的代理规则 watch: { ignored: (filePath) => watchOptionsIgnored(filePath, VITE_APP_YUXP_WATCH_IGNORED), }, }, build: { // 构建配置 target: 'es2015', // 设置目标浏览器兼容版本 sourcemap: false, // 是否生成源码映射 chunkSizeWarningLimit: 2000, // 设置块大小警告限制 reportCompressedSize: false, // 是否报告压缩后的大小 minify: 'terser', cssMinify: false, terserOptions: { compress: { drop_debugger: true, drop_console: true, }, }, }, }); };