100 lines
2.6 KiB
TypeScript
100 lines
2.6 KiB
TypeScript
// 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',
|
|
},
|
|
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: 'fade',
|
|
mode: 'out-in',
|
|
type: 'transition', // 明确指定动画类型
|
|
duration: {
|
|
enter: 200,
|
|
leave: 500
|
|
},
|
|
appear: true
|
|
}
|
|
},
|
|
hooks: {
|
|
'listen': (server) => {
|
|
startBroswer(server.address())
|
|
},
|
|
}
|
|
})
|
|
|
|
// 首次启动浏览器
|
|
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)
|
|
}
|
|
}
|
|
}
|