import { fileURLToPath, URL } from 'node:url'; const config = require('./package.json'); import { defineConfig, loadEnv } from 'vite'; import vue from '@vitejs/plugin-vue'; import AutoImport from 'unplugin-auto-import/vite'; import Components from 'unplugin-vue-components/vite'; import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'; import zipPack from 'vite-plugin-zip-pack'; import cleanPlugin from 'vite-plugin-clean'; import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'; import { resolve } from 'path'; const version = config.version; let proxyTarget = 'http://www.artprofessor.cn:3202/'; //let proxyTarget = 'http://localhost:3202/'; export default defineConfig(({ command, mode }) => { const env = loadEnv(mode, process.cwd()); const projectName = env.VITE_APP_PROJECTNAME; const outDir = `E:/work/go_cellsys/branches/art/web/Main/${projectName}`; return { base: '/' + projectName, build: { outDir: `E:/work/go_cellsys/branches/art/web/Main/${projectName}`, rollupOptions: { output: { chunkFileNames: 'js/[name]-[hash].js', // 引入文件名的名称 entryFileNames: 'js/[name]-[hash].js', // 包的入口文件名称 assetFileNames: '[ext]/[name]-[hash].[ext]', // 资源文件像 字体,图片等 }, }, }, server: { port: '8082', // 端口号,一般情况下为8080 proxy: { '/api/v2': { target: proxyTarget, ws: true, changeOrigin: true, }, '/oauth': { target: proxyTarget, ws: true, changeOrigin: true, }, '/cellsysProgramCollection': { target: proxyTarget, ws: true, changeOrigin: true, }, '/resources/': { target: proxyTarget, ws: true, changeOrigin: true, }, '/cellsys/api': { target: proxyTarget, ws: true, changeOrigin: true, }, '/ThirdpartyApi': { //第三方程序图片上传服务接口 target: proxyTarget, ws: true, changeOrigin: true, }, }, }, plugins: [ vue(), createSvgIconsPlugin({ // 这个是自己配置的图标路径,指出来(自己咋配置的咋来) iconDirs: [resolve(process.cwd(), 'src/icons/svg')], // 这个表示id,按这个来就对了 symbolId: 'icon-[dir]-[name]', }), cleanPlugin({ targetFiles: [outDir], }), // AutoImport({ // resolvers: [ElementPlusResolver()], // }), // Components({ // resolvers: [ElementPlusResolver()], // }), /* zipPack({ inDir: 'dist', // 输入的文件夹,就是要打包的文件夹 outDir: 'archive', // 打包好的 zip 文件放到哪个文件夹下 outFileName: `my-project-${new Date().toISOString().slice(0, 10)}.zip`, // 打包好的文件名 pathPrefix: '', }), VitePluginDistZipJs({ zipName: `artrepair v${version}`, // 压缩包名称 zipDir: 'dist', // 压缩文件存放路径,相对于项目根目录,为空时为打包输出文件夹 dayjsFormat: '', includeDistDir: true, }),*/ ], resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)), css: fileURLToPath(new URL('./src/assets/css', import.meta.url)), pc: fileURLToPath(new URL('./src/assets/css/pc', import.meta.url)), mobile: fileURLToPath(new URL('./src/assets/css/mobile', import.meta.url)), }, extensions: ['.vue', '.js', '.json'], }, }; });