157 lines
3.7 KiB
TypeScript
157 lines
3.7 KiB
TypeScript
// https://nuxt.com/docs/api/configuration/nuxt-config
|
||
import { config } from 'dotenv'
|
||
|
||
// 加载环境变量
|
||
config({ path: '../.env' })
|
||
|
||
export default defineNuxtConfig({
|
||
compatibilityDate: '2025-07-15',
|
||
devtools: { enabled: false },
|
||
|
||
// 开发服务器配置 - 允许外网访问
|
||
devServer: {
|
||
host: '0.0.0.0', // 改为0.0.0.0以允许外网访问
|
||
port: process.env.NUXT_DEV_PORT || 8080,
|
||
},
|
||
|
||
// 禁用默认布局,确保每个页面使用独立布局
|
||
app: {
|
||
layoutTransition: false,
|
||
pageTransition: false,
|
||
},
|
||
|
||
// 启用 SSR 以获得更好的构建结果
|
||
ssr: false,
|
||
|
||
// 路径别名配置 - 使用 pnpm workspace 包引用
|
||
alias: {
|
||
'@nuxt4crud/shared': '@nuxt4crud/shared',
|
||
},
|
||
|
||
// Vite 配置
|
||
vite: {
|
||
build: {
|
||
rollupOptions: {
|
||
output: {
|
||
manualChunks: {
|
||
'element-plus': ['element-plus'],
|
||
'vue-vendor': ['vue'],
|
||
},
|
||
},
|
||
},
|
||
// 确保以 ES 模块模式构建
|
||
commonjsOptions: {
|
||
transformMixedEsModules: true,
|
||
},
|
||
},
|
||
// 解决 CSS 中 import.meta 的问题
|
||
css: {
|
||
devSourcemap: true,
|
||
// 确保 CSS 预处理器正确工作
|
||
preprocessorOptions: {
|
||
scss: {
|
||
api: 'modern-compiler', // 使用现代编译器 API
|
||
},
|
||
},
|
||
},
|
||
// 配置 ES 模块处理
|
||
esbuild: {
|
||
target: 'es2020',
|
||
},
|
||
optimizeDeps: {
|
||
esbuildOptions: {
|
||
target: 'es2020',
|
||
},
|
||
},
|
||
},
|
||
|
||
// 构建优化
|
||
build: {
|
||
transpile: ['element-plus/es'],
|
||
},
|
||
|
||
modules: [
|
||
'@nuxt/eslint',
|
||
'@nuxt/image',
|
||
'@element-plus/nuxt',
|
||
'@nuxtjs/tailwindcss',
|
||
'@pinia/nuxt',
|
||
],
|
||
|
||
// Pinia配置
|
||
pinia: {
|
||
autoImports: [
|
||
// 自动导入defineStore和storeToRefs
|
||
'defineStore',
|
||
'storeToRefs',
|
||
],
|
||
},
|
||
|
||
// 指定 TailwindCSS 的全局样式入口文件
|
||
tailwindcss: {
|
||
cssPath: '~/assets/css/main.css',
|
||
},
|
||
|
||
// PostCSS 配置 - 替代 postcss.config.js
|
||
postcss: {
|
||
plugins: {
|
||
'tailwindcss/nesting': {},
|
||
tailwindcss: {},
|
||
autoprefixer: {},
|
||
},
|
||
},
|
||
|
||
elementPlus: {
|
||
/** Options */
|
||
// 自动导入样式
|
||
importStyle: 'scss',
|
||
// 启用组件和指令缓存(仅在开发模式下有效)
|
||
cache: true,
|
||
// 手动配置需要安装的方法
|
||
installMethods: ['ElLoading', 'ElMessage', 'ElMessageBox', 'ElNotification'],
|
||
// 全局配置
|
||
config: {
|
||
size: 'default',
|
||
zIndex: 3000,
|
||
},
|
||
},
|
||
|
||
// API 代理配置,移除Express代理,使用Nitro内置API
|
||
nitro: {
|
||
scanDirs: ['../server/api', '../server/routes'],
|
||
srcDir: '../server',
|
||
unstorage: {
|
||
driver: 'fs',
|
||
base: '../.data/db',
|
||
},
|
||
output: {
|
||
serverDir: '.output/server',
|
||
},
|
||
ignore: ['../scripts/**'],
|
||
prerender: {
|
||
crawlLinks: false,
|
||
routes: [],
|
||
},
|
||
},
|
||
|
||
// 运行时配置
|
||
runtimeConfig: {
|
||
// 私有配置,只在服务端可用
|
||
feishuAppId: process.env.FEISHU_APP_ID || 'cli_a62aaf3d9d385013',
|
||
feishuAppSecret: process.env.FEISHU_APP_SECRET || 'VH46dJI4T4bbUD7rI9J6Se2EI5rWVpBf',
|
||
cozeApiToken:
|
||
process.env.COZE_API_TOKEN ||
|
||
'pat_7VvJA4an8IbsjmID9SasNBZyVDCJ3NamxwBOBdDxfUQEnGOYGaQf3odBUoibO0aF',
|
||
cozeClientId: process.env.COZE_CLIENT_ID || '27608009841040583568491680329534.app.coze',
|
||
cozeClientSecret:
|
||
process.env.COZE_CLIENT_SECRET || 'Bx7ctHOQlzWVdoaQnSYJgRPwlK64IUuhi4oPnRO3OyJ5K4yc',
|
||
|
||
// 公共配置,客户端和服务端都可用
|
||
public: {
|
||
// 更新API基础路径,不再指向Express服务器
|
||
apiBase: process.env.NUXT_PUBLIC_API_BASE || '',
|
||
cozeDefaultWorkflowId: process.env.COZE_DEFAULT_WORKFLOW_ID || '7554970254934605859',
|
||
},
|
||
},
|
||
})
|