mirror of
https://github.com/setube/ogame-vue-ts.git
synced 2026-05-12 07:55:11 +08:00
refactor(server): 动态导入open模块以优化启动性能
- 将open模块的引入方式从同步改为动态导入 - 避免在服务器启动时立即加载不必要的依赖 - 提升应用初始化速度和资源利用率 - 确保浏览器自动打开功能正常运行 - 添加错误处理以应对模块加载失败情况
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const path = require('node:path');
|
const path = require('node:path');
|
||||||
const openUrl = require('open');
|
|
||||||
const os = require('node:os');
|
const os = require('node:os');
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
@@ -37,6 +36,7 @@ const server = app.listen(0, HOST, async () => {
|
|||||||
|
|
||||||
// 3. 自动打开浏览器
|
// 3. 自动打开浏览器
|
||||||
try {
|
try {
|
||||||
|
const { default: openUrl } = await import('open');
|
||||||
await openUrl(url);
|
await openUrl(url);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('无法自动打开浏览器:', err);
|
console.error('无法自动打开浏览器:', err);
|
||||||
|
|||||||
Reference in New Issue
Block a user