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.

251 lines
7.1 KiB
TypeScript

1 month ago
import { compile } from "vue";
import { loadEnv } from 'vite'
1 month ago
import { H3Event, type EventHandlerRequest } from 'h3'
import type { PrerenderRoute } from 'nitropack'
1 month ago
const env = loadEnv(process.env.NODE_ENV, process.cwd(), '')
// 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: '/img/KEP001.png' }
1 month ago
]
1 month ago
},
buildAssetsDir: '/_nuxt/', // 默认值
1 month ago
},
1 month ago
// ssr: true,
debug: false,
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访问路径未加载成功',
1 month ago
baseURL: env.NUXT_PUBLIC_API_BASE || '配置未成功读取,请检查配置文件',
cookieName: 'auth_data',
1 month ago
}
},
compatibilityDate: '2025-05-15',
1 month ago
devtools: { enabled: false },
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", '@element-plus/nuxt', 'nuxt-proxy', '@nuxtjs/device'],
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: {
1 month ago
preset: 'node-server',
1 month ago
// 缩小捆绑包
minify: true,
// 关闭源映射生成
sourceMap: false,
experimental: {
websocket: true // 启用 WebSocket 支持
},
devProxy: {
1 month ago
// '/event': {
// target: env.VITE_WS_URL || '配置未成功读取,请检查配置文件',
// changeOrigin: true,
// ws: true, // 启用 WebSocket 代理
// },
// '/drawHub': {
// target: env.VITE_SIGNALR_URL || '配置未成功读取,请检查配置文件',
// changeOrigin: true,
// ws: true
// },
// '/api/': {
// target: env.VITE_API_URL,
// changeOrigin: true,
// rewrite: (path: string) => path.replace(/^\/api/, ''),
// configure: (proxy: any) => {
// proxy.on('proxyReq', (proxyReq: any) => {
// // 确保代理传递所有方法
// // proxyReq.setHeader('Access-Control-Allow-Origin', 'http://localhost:3001');
// proxyReq.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
// proxyReq.setHeader('Access-Control-Allow-Headers', 'Content-Type,Authorization');
// proxyReq.setHeader('Access-Control-Allow-Credentials', 'true');
// });
// }
// },
// server: {
// cors: {
// origin: [
// 'http://localhost:3001'
// ],
// credentials: true
// }
// }
1 month ago
},
1 month ago
// routeRules: {
// '/api/**': {
// cors: true,
1 month ago
// headers: {
1 month ago
// 'Access-Control-Allow-Credentials': 'true',
// 'Access-Control-Allow-Origin': process.env.ALLOWED_ORIGIN || '*'
// }
// }
// }
// '/drawHub': {
// target: env.VITE_SIGNALR_URL || '配置未成功读取,请检查配置文件',
// changeOrigin: true,
// ws: true
// },
// server: {
// cors: {
// origin: [
// 'http://localhost:3000'
// ],
// credentials: true
// }
// },
// '/api': {
// target: 'http://localhost:10001',
// changeOrigin: true,
// headers: {
// '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: 3001,
// },
1 month ago
pinia: {
// 指定store目录
1 month ago
storeDir: "./stores",
autoImports: [
'defineStore',
'acceptHMRUpdate',
['defineStore', 'definePiniaStore']
]
1 month ago
},
imports: {
dirs: ['stores', 'composables', 'services']
},
plugins: [
//'~/plugins/drawerRuler.js
'~/plugins/element-plus.client.ts',
'~/plugins/progressBar.client.ts',
'~/plugins/echarts.client.ts',
1 month ago
'~/plugins/cookie.client.ts',
'~/plugins/cookie.server.ts',
'~/plugins/auth-init.client.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); // 检查是否包含目标变量
// },
// 'vue.setup'(app: any) {
// //
// if (typeof window !== 'undefined') {
// require('resize-observer-polyfill')
1 month ago
// }
1 month ago
// },
1 month ago
// 'pages.extend'(pages) {
// pages.forEach((page) => {
// if (page.path.startsWith('/')) {
// page.meta = page.meta || {};
// page.meta.requiresAuth = true;
// }
// });
// }
1 month ago
// hooks: {
// 'prerender:routes'(routes: PrerenderRoute[]) {
// console.log('Prerendering routes:', routes)
// }
// }
1 month ago
},
// routeRules: {
// '/**': {
// meta: { requiresAuth: true } // 自动为匹配路径添加 meta
// }
// }
router: {
middleware: ['auth']
}
})