2024-01-05 21:02:11 +08:00
|
|
|
|
import { ConfigEnv, defineConfig, loadEnv } from 'vite'
|
2023-12-17 02:21:55 +08:00
|
|
|
|
import vue from '@vitejs/plugin-vue'
|
2023-12-16 03:56:10 +08:00
|
|
|
|
import AutoImport from 'unplugin-auto-import/vite' //自动导入
|
|
|
|
|
import Components from 'unplugin-vue-components/vite' //组件注册
|
2023-12-17 02:21:55 +08:00
|
|
|
|
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'
|
2023-12-16 03:56:10 +08:00
|
|
|
|
import { getRootPath, getSrcPath } from './build/config/getPath'
|
2023-12-17 02:21:55 +08:00
|
|
|
|
import vueJsx from '@vitejs/plugin-vue-jsx'
|
2024-01-10 02:18:32 +08:00
|
|
|
|
import unocss from '@unocss/vite'
|
2024-03-06 08:03:27 +08:00
|
|
|
|
import terser from '@rollup/plugin-terser'
|
2024-04-29 21:20:01 +08:00
|
|
|
|
import { atStartup } from './build/config/console'
|
2023-12-15 20:25:35 +08:00
|
|
|
|
|
|
|
|
|
// https://vitejs.dev/config/
|
2024-04-22 23:32:09 +08:00
|
|
|
|
/**! 不需要优化前端打包(如开启gzip) */
|
2024-01-05 21:02:11 +08:00
|
|
|
|
export default defineConfig(({ mode }: ConfigEnv) => {
|
2023-12-16 03:56:10 +08:00
|
|
|
|
// 获取当前环境的配置,如何设置第三个参数则加载所有变量,而不是以“VITE_”前缀的变量
|
2024-04-29 21:20:01 +08:00
|
|
|
|
const config = loadEnv(mode, process.cwd())
|
2023-12-16 03:56:10 +08:00
|
|
|
|
return {
|
|
|
|
|
resolve: {
|
|
|
|
|
alias: {
|
|
|
|
|
// 配置路径别名@
|
|
|
|
|
'@': getSrcPath(),
|
|
|
|
|
// 配置路径别名~(根路径)
|
|
|
|
|
'~': getRootPath()
|
|
|
|
|
}
|
2023-12-15 20:25:35 +08:00
|
|
|
|
},
|
2024-01-21 09:59:18 +08:00
|
|
|
|
css: {
|
|
|
|
|
preprocessorOptions: {
|
|
|
|
|
scss: {
|
2024-09-28 22:18:32 +08:00
|
|
|
|
additionalData: '@use "./src/styles/scss/global/variable.scss" as *;' // 加载全局样式,使用scss特性
|
2024-01-21 09:59:18 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2024-01-15 06:14:04 +08:00
|
|
|
|
define: {
|
|
|
|
|
// enable hydration mismatch details in production build 3.4新增水化不匹配的警告
|
|
|
|
|
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: 'true'
|
|
|
|
|
},
|
2023-12-16 03:56:10 +08:00
|
|
|
|
plugins: [
|
2024-04-29 21:20:01 +08:00
|
|
|
|
/**! 启动时候打印项目信息(不需要可关闭) */
|
|
|
|
|
atStartup(config, mode),
|
2023-12-16 03:56:10 +08:00
|
|
|
|
/**
|
2024-09-13 17:49:21 +08:00
|
|
|
|
* vue3.5.0已支持解构并具有响应式
|
2023-12-16 03:56:10 +08:00
|
|
|
|
* */
|
2024-09-13 17:49:21 +08:00
|
|
|
|
vue(),
|
2023-12-17 02:21:55 +08:00
|
|
|
|
vueJsx(), // 开启jsx功能
|
2024-01-10 02:18:32 +08:00
|
|
|
|
unocss(), // 开启unocss
|
2023-12-16 03:56:10 +08:00
|
|
|
|
AutoImport({
|
2024-09-22 23:18:13 +08:00
|
|
|
|
imports: [
|
|
|
|
|
'vue',
|
|
|
|
|
'vue-router',
|
|
|
|
|
'pinia',
|
|
|
|
|
{ 'naive-ui': ['useDialog', 'useMessage', 'useNotification', 'useLoadingBar', 'useModal'] }
|
|
|
|
|
],
|
2023-12-16 03:56:10 +08:00
|
|
|
|
dts: 'src/typings/auto-imports.d.ts'
|
|
|
|
|
}),
|
2024-04-22 02:24:36 +08:00
|
|
|
|
/**自动导入组件,但是不会自动导入jsx和tsx*/
|
2023-12-16 03:56:10 +08:00
|
|
|
|
Components({
|
2024-01-10 02:18:32 +08:00
|
|
|
|
dirs: ['src/components/**'], // 设置需要扫描的目录
|
2023-12-16 03:56:10 +08:00
|
|
|
|
resolvers: [NaiveUiResolver()],
|
|
|
|
|
dts: 'src/typings/components.d.ts'
|
2024-03-06 08:03:27 +08:00
|
|
|
|
}),
|
2024-04-22 02:24:36 +08:00
|
|
|
|
/** 压缩代码 */
|
2024-03-06 08:03:27 +08:00
|
|
|
|
terser({
|
|
|
|
|
format: {
|
|
|
|
|
comments: false // 移除所有注释
|
|
|
|
|
},
|
|
|
|
|
compress: {
|
|
|
|
|
drop_console: true, // 移除 console.log
|
|
|
|
|
drop_debugger: true // 移除 debugger
|
|
|
|
|
}
|
2023-12-17 02:21:55 +08:00
|
|
|
|
})
|
2023-12-16 03:56:10 +08:00
|
|
|
|
],
|
2024-03-06 08:03:27 +08:00
|
|
|
|
build: {
|
|
|
|
|
cssCodeSplit: true, // 启用 CSS 代码拆分
|
|
|
|
|
minify: 'terser', // 指定使用哪种混淆器
|
|
|
|
|
// chunk 大小警告的限制(kb)
|
|
|
|
|
chunkSizeWarningLimit: 1200,
|
|
|
|
|
// 分包配置
|
|
|
|
|
rollupOptions: {
|
|
|
|
|
output: {
|
|
|
|
|
chunkFileNames: 'static/js/[name]-[hash].js', // 引入文件名的名称
|
|
|
|
|
entryFileNames: 'static/js/[name]-[hash].js', // 包的入口文件名称
|
|
|
|
|
assetFileNames: 'static/[ext]/[name]-[hash].[ext]', // 资源文件像 字体,图片等
|
|
|
|
|
// 最小化拆分包
|
|
|
|
|
manualChunks(id) {
|
|
|
|
|
if (id.includes('node_modules')) {
|
2024-03-17 00:00:50 +08:00
|
|
|
|
return 'invariable'
|
2024-03-06 08:03:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2023-12-16 03:56:10 +08:00
|
|
|
|
|
|
|
|
|
// Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
|
|
|
|
|
//
|
|
|
|
|
// 1. prevent vite from obscuring rust errors
|
|
|
|
|
clearScreen: false,
|
|
|
|
|
// 2. tauri expects a fixed port, fail if that port is not available
|
|
|
|
|
server: {
|
2024-05-05 01:38:12 +08:00
|
|
|
|
//配置跨域
|
|
|
|
|
proxy: {
|
|
|
|
|
'/api': {
|
|
|
|
|
// “/api” 以及前置字符串会被替换为真正域名
|
|
|
|
|
target: config.VITE_SERVICE_URL, // 请求域名
|
|
|
|
|
changeOrigin: true, // 是否跨域
|
|
|
|
|
rewrite: (path) => path.replace(/^\/api/, '')
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
hmr: true, // 热更新
|
|
|
|
|
cors: true, // 配置 CORS
|
2023-12-16 03:56:10 +08:00
|
|
|
|
host: '0.0.0.0',
|
|
|
|
|
port: 6130,
|
|
|
|
|
strictPort: true,
|
|
|
|
|
watch: {
|
|
|
|
|
// 3. tell vite to ignore watching `src-tauri`
|
2023-12-17 02:21:55 +08:00
|
|
|
|
ignored: ['**/src-tauri/**']
|
|
|
|
|
}
|
2023-12-16 03:56:10 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|