starwait/nuxt.config.ts
2025-04-25 11:33:24 +08:00

147 lines
4.1 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.

// https://nuxt.com/docs/api/configuration/nuxt-config
// 每次热更新都会执行defineNuxtConfig
import {exec} from "node:child_process";
import open, {apps} from "open";
import type {AddressInfo} from "node:net";
export default defineNuxtConfig({
compatibilityDate: '2024-11-01',
devtools: { enabled: true },
modules: ['@nuxt/eslint', '@nuxtjs/tailwindcss'],
devServer: {
host: '0.0.0.0',
port: 3000,
},
features: {
devLogs: 'silent' // 这是默认值,确保它没有被设置为 true日志区分server和client false为不在client打印
},
css: [
'~/assets/css/style.css',
'~/assets/css/font.css',
'~/assets/css/value.css',
'~/assets/css/iconfont.css',
'~/assets/css/transitions.css',
],
app:{
head:{
link: [
{
// LXGW WenKai 落霞孤鹜
rel: "stylesheet",
href: 'https://chinese-fonts-cdn.deno.dev/packages/lxgwwenkai/dist/LXGWWenKai-Regular/result.css'
},
{
// Huiwen-mincho 汇文明朝体
rel: "stylesheet",
href: 'https://chinese-fonts-cdn.deno.dev/packages/hwmct/dist/%E6%B1%87%E6%96%87%E6%98%8E%E6%9C%9D%E4%BD%93/result.css'
// article {
// font-family:'Huiwen-mincho';
// font-weight:'400'
// };
},
]
},
layoutTransition:{
name: 'indexFade',
mode: 'out-in',
type: 'transition', // 明确指定动画类型
duration: {
enter: 300,
leave: 300
},
appear: true
},
},
hooks: {
'listen': (server) => {
startBroswer(server.address())
},
},
runtimeConfig: {
redis: {
host: process.env.REDIS_HOST || '127.0.0.1',
port: Number(process.env.REDIS_PORT) || 6379,
connectName: 'star-writ',
database: Number(process.env.REDIS_DB) || 9,
username: 'default',
password: process.env.REDIS_PASSWORD || 'Hxl1314521',
},
mysql:{
host: process.env.DB_HOST || '127.0.0.1',
port: Number(process.env.DB_PORT) || 3306,
user: process.env.DB_USER || 'root',
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME || 'yuheng',
// ssl:
// process.env.NODE_ENV === 'production'
// ? {
// rejectUnauthorized: false,
// servername: '', // 明确置空servername参数
// }
// : null,
},
jwt: {
secret: process.env.JWT_SECRET || 'Hxl1314521',
accessExpiresIn: process.env.JWT_ACCESS_EXPIRES || '20m',
refreshExpiresIn: process.env.JWT_REFRESH_EXPIRES || '14d',
whitelist: [
'/user/login',
'/user/register',
'/user/refreshToken',
'/',
// '/module',
'/docs*',
'/docs/json'
],
},
defaultToken: {
username: process.env.USERNAME || 'expressgy',
nickname: process.env.PASSWORD || 'Nie',
userId: '1'
}
},
})
// 首次启动浏览器
async function startBroswer(address: AddressInfo | string | null) {
if(!process.env.START){
if (address && typeof address !== 'string') {
console.log('Hooks: Listen')
const host = address.address === '::' ? 'localhost' : address.address
const port = address.port
const url = `http://${host}:${port}`;
try {
await open(url, {
app: {
name: apps.chrome,
arguments: [
'--remote-debugging-port=9222',
'--auto-open-devtools-for-tabs'
]
}
});
} catch (e) {
console.error((e as Error).message)
switch (process.platform) {
case 'win32':
console.log('Windows 系统');
exec(`start ${url}`)
break;
case 'darwin':
console.log('macOS 系统');
exec(`open ${url}`)
break;
case 'linux':
console.log('Linux 系统');
exec(`xdg-open ${url}`)
break;
default:
console.log('其他系统:', process.platform);
}
}
process.env.START = String(true)
}
}
}