You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

205 lines
5.4 KiB
TypeScript

1 month ago
import { compile } from "vue";
import { loadEnv } from 'vite'
const env = loadEnv(process.env.NODE_ENV, process.cwd(), '')
1 month ago
// console.log("ENV",env);
1 month ago
// https://nuxt.com/docs/api/configuration/nuxt-config
export default ({
app: {
head: {
title: "KEP图形处理分析软件Web版",
charset: 'utf-8',
htmlAttrs: {
lang: 'zh-CN'
},
link: [
1 month ago
{ rel: 'icon', type: 'image/png', href: '_nuxt/assets/img/KEP001.png' }
1 month ago
]
1 month ago
}
1 month ago
},
1 month ago
debug: true,
1 month ago
runtimeConfig: {
public: {
wsUrl: env.VITE_WS_URL || '配置未成功读取,请检查配置文件', // WebSocket URL
// 图片加载路径
imgUrl: env.VITE_IMG_URL || '配置未成功读取,请检查配置文件',
// 数据缓存目录
dataDir: env.VITE_DATA_DIR || '配置未成功读取,请检查配置文件',
// 请求后端API地址
apiBaseUrl: env.VITE_API_URL || '配置未成功读取,请检查配置文件',
apiTimeout: env.VITE_API_TIMEOUT ? parseInt(env.VITE_API_TIMEOUT) : 10000, // API请求超时时间
signalRUrl: env.VITE_SIGNALR_URL || 'SIGNALR访问路径未加载成功',
}
},
compatibilityDate: '2025-05-15',
1 month ago
devtools: { enabled: true },
1 month ago
typescript: {
strict: true,
typeCheck: true,
shim: false,
tsConfig: {
compilerOptions: {
// 允许更灵活的类型赋值
strictNullChecks: false
}
}
},
css: ['~/assets/css/main.css',
'~/assets/css/reset.css',
'element-plus/dist/index.css',
'~/assets/css/element-overrides.scss',
'~/assets/css/transitions.css'],
1 month ago
modules: ["@pinia/nuxt", '@nuxt/icon', '@element-plus/nuxt', 'nuxt-proxy', '@nuxt/ui'],
1 month ago
elementPlus: {
importStyle: 'css',
importLocale: 'zh-CN',
},
// 确保正确处理环境变量
1 month ago
sourcemap: env.NODE_ENV !== 'production',
1 month ago
build: {
// 添加图片加载器
loaders: {
imgUrl: { limit: 8192 } // 小于8KB转base64
},
transpile: ['element-plus', 'vue-toastification']
},
image: {
presets: {
custom: { modifiers: { format: 'webp' } }
}
},
icon: {
customCollections: [
{
prefix: 'c-icon',
dir: './assets/icons'
}
]
},
nitro: {
// 缩小捆绑包
minify: true,
// 关闭源映射生成
sourceMap: false,
experimental: {
websocket: true // 启用 WebSocket 支持
},
devProxy: {
1 month ago
'/socket.io/': {
target: env.VITE_WS_URL || '配置未成功读取,请检查配置文件',
changeOrigin: true,
ws: true, // 启用 WebSocket 代理
},
'/drawHub': {
target: env.VITE_SIGNALR_URL || '配置未成功读取,请检查配置文件',
changeOrigin: true,
ws: true
}
},
'/api': {
target: 'http://localhost:3000',
changeOrigin: true
},
'/drawHub': {
target: env.VITE_SIGNALR_URL || '配置未成功读取,请检查配置文件',
changeOrigin: true,
ws: true
1 month ago
},
1 month ago
server: {
cors: {
origin: [
'http://localhost:3000'
],
credentials: true
}
}
// '/User':{
// target:'http://localhost:10001',
// changeOrigin:true,
1 month ago
// headers: {
1 month ago
// 'X-Proxy': 'Nuxt-Dev-Server'
// },
1 month ago
// 添加这些CORS相关头确保代理请求正确处理
// onResponse: (event, { response, options }) => {
// // 设置CORS头确保前端可以正确接收响应
// response.headers.set('Access-Control-Allow-Origin', 'http://localhost:3000');
// response.headers.set('Access-Control-Allow-Methods', 'GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS');
// response.headers.set('Access-Control-Allow-Headers', 'Content-Type,Authorization');
// response.headers.set('Access-Control-Allow-Credentials', 'true');
// }
// }
},
1 month ago
server: {
host: '0.0.0.0',
port: 3000,
},
1 month ago
pinia: {
// 指定store目录
1 month ago
storeDir: "./stores"
1 month ago
},
imports: {
dirs: ['stores', 'composables', 'services']
},
plugins: [
//'~/plugins/drawerRuler.js
1 month ago
1 month ago
'~/plugins/element-plus.client.ts',
'~/plugins/progressBar.client.ts',
'~/plugins/echarts.client.ts',
1 month ago
// '~/plugins/authInit.ts',
1 month ago
],
vite: {
css: {
preprocessorOptions: {
scss: {
additionalData: `
@use "@/assets/element-variables.scss" as *;
`
}
}
},
// plugins: [
// {
// name: 'log-env-vars',
// configResolved(config:any) {
// console.log('=== Vite 加载的环境变量 ===');
// console.log(config.env); // 检查是否包含 VITE_XXX 变量
// }
// }
// ]
},
hooks: {
1 month ago
// // 在服务端构建完成后打印环境变量
// 'build:done': () => {
// console.log('=== 环境变量加载结果 ===');
// console.log(process.env); // 检查是否包含目标变量
1 month ago
// }
1 month ago
'vue.setup'(app: any) {
//
if (typeof window !== 'undefined') {
require('resize-observer-polyfill')
}
},
1 month ago
// 'pages.extend'(pages) {
// pages.forEach((page) => {
// if (page.path.startsWith('/')) {
// page.meta = page.meta || {};
// page.meta.requiresAuth = true;
// }
// });
// }
},
// routeRules: {
// '/**': {
// meta: { requiresAuth: true } // 自动为匹配路径添加 meta
// }
// }
router: {
middleware: ['auth']
}
})