go-viee-fetch-Demo/vite.config.ts
gaohaifeng 5752682808 fix: 修复API请求配置和代理设置
更新vite配置中的代理目标地址并添加路径重写规则
统一使用axiosInstance替代直接axios调用
移除未使用的axios导入并设置baseURL为空
2025-09-02 13:47:51 +08:00

136 lines
3.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import { OUTPUT_DIR, brotliSize, chunkSizeWarningLimit, terserOptions, rollupOptions } from './build/constant'
import viteCompression from 'vite-plugin-compression'
import { axiosPre } from './src/settings/httpSetting'
import { viteMockServe } from 'vite-plugin-mock'
import monacoEditorPlugin from 'vite-plugin-monaco-editor'
function pathResolve(dir: string) {
return resolve(process.cwd(), '.', dir)
}
export default ({ mode }) =>
defineConfig({
// base: process.env.NODE_ENV === 'production' ? '/dl_jcsy/' : './',
base: process.env.NODE_ENV === 'production' ? '/jtdp/' : './',
// 路径重定向
resolve: {
alias: [
{
find: /\/#\//,
replacement: pathResolve('types')
},
{
find: '@',
replacement: pathResolve('src')
},
{
find: 'vue-i18n',
replacement: 'vue-i18n/dist/vue-i18n.cjs.js' //解决i8n警告
},
{
find: 'async-validator',
replacement: 'node_modules/async-validator/dist-node/index.js' //解决async-validator警告
}
],
dedupe: ['vue']
},
// 全局 css 注册
css: {
preprocessorOptions: {
scss: {
javascriptEnabled: true,
additionalData: `@import "src/styles/common/style.scss";`
}
}
},
// 开发服务器配置
server: {
host: true,
open: true,
port: 3000,
proxy: {
[axiosPre]: {
// @ts-ignore
target: loadEnv(mode, process.cwd()).VITE_DEV_PATH,
changeOrigin: true,
ws: true,
secure: true
},
'/aw/': {
target: 'http://127.0.0.1:8080/',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/aw/, '')
},
'/awjt/': {
target: 'http://127.0.0.1:8080/',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/awjt/, '')
},
// '/awjt/': {
// target: 'http://127.0.0.1:8921/',
// changeOrigin: true
// },
'/dev': {
target: 'http://127.0.0.1:8080',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/dev/, '')
},
'/screen/': {
target: 'http://127.0.0.1:8080/',
changeOrigin: true
}
}
},
define: {
// enable hydration mismatch details in production build
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: 'true'
},
plugins: [
vue({
template: {
compilerOptions: {
// 排除 iconify 图标影子组件编译报错
isCustomElement: tag => tag.startsWith('iconify-icon')
}
}
}),
monacoEditorPlugin({
languageWorkers: ['editorWorkerService', 'typescript', 'json', 'html']
}),
viteMockServe({
mockPath: '/src/api/mock',
// 开发打包开关
localEnabled: true,
// 生产打包开关
prodEnabled: true,
// 打开后,可以读取 ts 文件模块。 请注意,打开后将无法监视.js 文件
supportTs: true,
// 监视文件更改
watchFiles: true
}),
// 压缩
viteCompression({
verbose: true,
disable: false,
threshold: 10240,
algorithm: 'gzip',
ext: '.gz'
})
],
build: {
target: 'es2020',
sourcemap: false,
outDir: OUTPUT_DIR,
minify: 'terser', // 如果需要用terser混淆可打开这两行
terserOptions: terserOptions,
rollupOptions: rollupOptions,
reportCompressedSize: brotliSize,
chunkSizeWarningLimit: chunkSizeWarningLimit
}
})