import { defineConfig } from 'vite' import vue from '@vitejs/plugin-vue' import { resolve } from 'path' import fs from 'fs'; import AutoImport from 'unplugin-auto-import/vite' import Components from 'unplugin-vue-components/vite' import { ElementPlusResolver } from 'unplugin-vue-components/resolvers' import Icons from 'unplugin-icons/vite' import IconsResolver from 'unplugin-icons/resolver' import topLevelAwait from 'vite-plugin-top-level-await' // 手动导入 import ElementPlus from 'unplugin-element-plus/vite' // https://vitejs.dev/config/ export default defineConfig(({ mode}) => { return{ base: './', css: { preprocessorOptions: { scss: { // 自定义的主题色 additionalData: `@use "@/assets/style/element/index.scss" as *;`, }, }, }, plugins: [ vue(), ElementPlus({ useSource: true, }), AutoImport({ imports: ["vue", "vue-router"], resolvers: [ IconsResolver(), ElementPlusResolver({ // 自动引入修改主题色添加这一行,使用预处理样式,不添加将会导致使用ElMessage,ElNotification等组件时默认的主题色会覆盖自定义的主题色 // importStyle: "sass", importStyle: mode === "development" ? false : "sass", }) ], }), Components({ resolvers: [ IconsResolver(), ElementPlusResolver({ // 自动引入修改主题色添加这一行,使用预处理样式 // importStyle: "sass", importStyle: mode === "development" ? false : "sass", }) ], }), Icons({ autoInstall: true, }), topLevelAwait({ // The export name of top-level await promise for each chunk module promiseExportName: '__tla', // The function to generate import names of top-level await promise in each chunk module promiseImportName: i => `__tla_${i}` }) ], server: { host: '0.0.0.0', //解决“vite use `--host` to expose” port: 8080, open: false, hmr:true, cors: true, // 允许跨域 proxy: { '/api': { target: "http://idea-ad.wenxingshuju.com", // target: "http://39.106.149.78:8001", changeOrigin: true, secure: false, }, } }, resolve:{ alias:[ { find:'@', replacement:resolve(__dirname,'src') } ] }, build: { outDir: "dist", // outDir:'../', // /** 打包后静态资源目录 */ // assetsDir: "./static", sourcemap: false, minify: 'terser', chunkSizeWarningLimit: 1500, terserOptions: { compress: { drop_console: false, drop_debugger: true } }, rollupOptions: { output: { manualChunks(id) { if (id.includes('node_modules')) { return id .toString() .split('node_modules/')[1] .split('/')[0] .toString(); } }, chunkFileNames: (chunkInfo) => { const facadeModuleId = chunkInfo.facadeModuleId ? chunkInfo.facadeModuleId.split('/') : []; const fileName = facadeModuleId[facadeModuleId.length - 2] || '[name]'; return `js/${fileName}/[name].[hash].js`; } } } }, } })