@kmlckj/licos-ai-cli 1.0.16 → 1.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -39,7 +39,7 @@ async function startServer(): Promise<Server> {
39
39
  app.use(router);
40
40
 
41
41
  // 集成 Vite(开发模式)或静态文件服务(生产模式)
42
- await setupVite(app);
42
+ await setupVite(app, server);
43
43
 
44
44
  // 全局错误处理
45
45
  app.use((err: Error, _req: express.Request, res: express.Response, _next: express.NextFunction) => {
@@ -1,6 +1,7 @@
1
1
  // ABOUTME: Vite integration for Express server
2
2
  // ABOUTME: Handles dev middleware and production static file serving
3
3
 
4
+ import type { Server } from 'http';
4
5
  import type { Application, Request, Response } from 'express';
5
6
  import express from 'express';
6
7
  import path from 'path';
@@ -23,7 +24,7 @@ function mountProjectAssets(app: Application) {
23
24
  /**
24
25
  * 集成 Vite 开发服务器(中间件模式)
25
26
  */
26
- export async function setupViteMiddleware(app: Application) {
27
+ export async function setupViteMiddleware(app: Application, httpServer: Server) {
27
28
  const [{ createServer: createViteServer }, { default: viteConfig }] = await Promise.all([
28
29
  import('vite'),
29
30
  import('../vite.config'),
@@ -33,6 +34,13 @@ export async function setupViteMiddleware(app: Application) {
33
34
  ...viteConfig,
34
35
  server: {
35
36
  ...viteConfig.server,
37
+ hmr:
38
+ viteConfig.server?.hmr === false
39
+ ? false
40
+ : {
41
+ ...(typeof viteConfig.server?.hmr === 'object' ? viteConfig.server.hmr : {}),
42
+ server: httpServer,
43
+ },
36
44
  middlewareMode: true,
37
45
  },
38
46
  appType: 'spa',
@@ -76,9 +84,9 @@ export function setupStaticServer(app: Application) {
76
84
  /**
77
85
  * 根据环境设置 Vite
78
86
  */
79
- export async function setupVite(app: Application) {
87
+ export async function setupVite(app: Application, httpServer: Server) {
80
88
  if (isDev) {
81
- await setupViteMiddleware(app);
89
+ await setupViteMiddleware(app, httpServer);
82
90
  } else {
83
91
  setupStaticServer(app);
84
92
  }
@@ -1,64 +1,64 @@
1
- import { defineConfig } from 'vite';
2
-
3
- function normalizeBasePath(value?: string): string {
4
- const trimmed = value?.trim();
5
- if (!trimmed || trimmed === '/') return '/';
6
- return `/${trimmed.replace(/^\/+|\/+$/g, '')}/`;
7
- }
8
-
9
- function isProdProjectEnv(value?: string): boolean {
10
- const normalized = value?.trim().toLowerCase();
11
- return normalized === 'prod' || normalized === 'production' || normalized === 'release';
12
- }
13
-
14
- const deployBasePath = process.env.VITE_BASE_PATH || process.env.BASE_PATH;
15
- const shouldUseBasePath = Boolean(deployBasePath) || isProdProjectEnv(process.env.LICOS_PROJECT_ENV);
16
-
17
- function parsePort(value?: string): number | undefined {
18
- const port = Number.parseInt(value || '', 10);
19
- return Number.isInteger(port) && port > 0 ? port : undefined;
20
- }
21
-
22
- function createPreviewHmrConfig() {
23
- if (!process.env.LICOS_PREVIEW_BASE_PATH) {
24
- return undefined;
25
- }
26
- const hmr: Record<string, unknown> = {
27
- overlay: true,
28
- path: process.env.LICOS_PREVIEW_HMR_PATH || '/hot/vite-hmr',
29
- timeout: 30000,
30
- };
31
- if (process.env.LICOS_PREVIEW_HMR_HOST) {
32
- hmr.host = process.env.LICOS_PREVIEW_HMR_HOST;
33
- }
34
- if (process.env.LICOS_PREVIEW_HMR_PROTOCOL) {
35
- hmr.protocol = process.env.LICOS_PREVIEW_HMR_PROTOCOL;
36
- }
37
- const clientPort = parsePort(process.env.LICOS_PREVIEW_HMR_CLIENT_PORT);
38
- if (clientPort) {
39
- hmr.clientPort = clientPort;
40
- }
41
- return hmr;
42
- }
43
-
44
- const previewHmrConfig = createPreviewHmrConfig();
45
-
46
- export default defineConfig({
47
- base: shouldUseBasePath ? normalizeBasePath(deployBasePath) : '/',
48
- server: {
49
- port: <%= port %>,
50
- host: '0.0.0.0',
51
- allowedHosts: true,
52
- hmr: previewHmrConfig || {
53
- overlay: true,
54
- path: '/hot/vite-hmr',
55
- port: <%= hmrPort %>,
56
- clientPort: 443,
57
- timeout: 30000,
58
- },
59
- watch: {
60
- usePolling: true,
61
- interval: 100,
62
- }
63
- },
64
- });
1
+ import { defineConfig } from 'vite';
2
+
3
+ function normalizeBasePath(value?: string): string {
4
+ const trimmed = value?.trim();
5
+ if (!trimmed || trimmed === '/') return '/';
6
+ return `/${trimmed.replace(/^\/+|\/+$/g, '')}/`;
7
+ }
8
+
9
+ function isProdProjectEnv(value?: string): boolean {
10
+ const normalized = value?.trim().toLowerCase();
11
+ return normalized === 'prod' || normalized === 'production' || normalized === 'release';
12
+ }
13
+
14
+ const deployBasePath = process.env.VITE_BASE_PATH || process.env.BASE_PATH;
15
+ const shouldUseBasePath = Boolean(deployBasePath) || isProdProjectEnv(process.env.LICOS_PROJECT_ENV);
16
+
17
+ function parsePort(value?: string): number | undefined {
18
+ const port = Number.parseInt(value || '', 10);
19
+ return Number.isInteger(port) && port > 0 ? port : undefined;
20
+ }
21
+
22
+ function createPreviewHmrConfig() {
23
+ if (!process.env.LICOS_PREVIEW_BASE_PATH) {
24
+ return undefined;
25
+ }
26
+ const hmr: Record<string, unknown> = {
27
+ overlay: true,
28
+ path: process.env.LICOS_PREVIEW_HMR_PATH || '/hot/vite-hmr',
29
+ timeout: 30000,
30
+ };
31
+ if (process.env.LICOS_PREVIEW_HMR_HOST) {
32
+ hmr.host = process.env.LICOS_PREVIEW_HMR_HOST;
33
+ }
34
+ if (process.env.LICOS_PREVIEW_HMR_PROTOCOL) {
35
+ hmr.protocol = process.env.LICOS_PREVIEW_HMR_PROTOCOL;
36
+ }
37
+ const clientPort = parsePort(process.env.LICOS_PREVIEW_HMR_CLIENT_PORT);
38
+ if (clientPort) {
39
+ hmr.clientPort = clientPort;
40
+ }
41
+ return hmr;
42
+ }
43
+
44
+ const previewHmrConfig = createPreviewHmrConfig();
45
+
46
+ export default defineConfig({
47
+ base: shouldUseBasePath ? normalizeBasePath(deployBasePath) : '/',
48
+ server: {
49
+ port: <%= port %>,
50
+ host: '0.0.0.0',
51
+ allowedHosts: true,
52
+ hmr: previewHmrConfig || {
53
+ overlay: true,
54
+ path: '/hot/vite-hmr',
55
+ port: <%= hmrPort %>,
56
+ clientPort: 443,
57
+ timeout: 30000,
58
+ },
59
+ watch: {
60
+ usePolling: true,
61
+ interval: 100,
62
+ }
63
+ },
64
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kmlckj/licos-ai-cli",
3
- "version": "1.0.16",
3
+ "version": "1.0.19",
4
4
  "description": "LICOS AI coding workspace CLI - project template engine and dev tools",
5
5
  "license": "MIT",
6
6
  "author": "kmlckj",