vite-plugin-blocklet 0.8.5 → 0.8.6
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.
- package/dist/index.cjs +20 -0
- package/libs/client.js +20 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -462,6 +462,8 @@ const isProduction = process.env.NODE_ENV === 'production' || process.env.ABT_NO
|
|
|
462
462
|
* @param {number} [options.clientPort] - The clientPort for the ws server.
|
|
463
463
|
* @param {string} [options.configFile=''] - The path to the config file.
|
|
464
464
|
* @param {string} [options.appType='spa'] - The type of the application.
|
|
465
|
+
* @param {import('node:http').Server} [options.server] - The http server instance
|
|
466
|
+
* @param {object} [options.importMetaHot] - vite import.meta.hot
|
|
465
467
|
* @return {Promise<Object>} A promise that resolves to the Vite server object.
|
|
466
468
|
*/
|
|
467
469
|
async function setupClient(app, options = {}) {
|
|
@@ -508,6 +510,24 @@ async function setupClient(app, options = {}) {
|
|
|
508
510
|
});
|
|
509
511
|
// 将 vite 的 connect 实例作中间件使用
|
|
510
512
|
app.use(vite$1.middlewares);
|
|
513
|
+
// 用于 vite-node 进行服务重载时,先关闭原有服务的端口监听
|
|
514
|
+
if (options?.server && options?.importMetaHot && options.importMetaHot?.on && options.importMetaHot?.dispose) {
|
|
515
|
+
async function killServer() {
|
|
516
|
+
await options.server.close((err) => {
|
|
517
|
+
console.log('vite-plugin-blocklet: Server closed succeed');
|
|
518
|
+
console.error('vite-plugin-blocklet: Failed to close server', err);
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
options.importMetaHot.on('vite:beforeFullReload', async () => {
|
|
522
|
+
console.log('vite-plugin-blocklet: Full reload');
|
|
523
|
+
await killServer();
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
options.importMetaHot.dispose(async () => {
|
|
527
|
+
console.log('vite-plugin-blocklet: Dispose');
|
|
528
|
+
await killServer();
|
|
529
|
+
});
|
|
530
|
+
}
|
|
511
531
|
return vite$1;
|
|
512
532
|
}
|
|
513
533
|
}
|
package/libs/client.js
CHANGED
|
@@ -19,6 +19,8 @@ const isProduction = process.env.NODE_ENV === 'production' || process.env.ABT_NO
|
|
|
19
19
|
* @param {number} [options.clientPort] - The clientPort for the ws server.
|
|
20
20
|
* @param {string} [options.configFile=''] - The path to the config file.
|
|
21
21
|
* @param {string} [options.appType='spa'] - The type of the application.
|
|
22
|
+
* @param {import('node:http').Server} [options.server] - The http server instance
|
|
23
|
+
* @param {object} [options.importMetaHot] - vite import.meta.hot
|
|
22
24
|
* @return {Promise<Object>} A promise that resolves to the Vite server object.
|
|
23
25
|
*/
|
|
24
26
|
export default async function setupClient(app, options = {}) {
|
|
@@ -65,6 +67,24 @@ export default async function setupClient(app, options = {}) {
|
|
|
65
67
|
});
|
|
66
68
|
// 将 vite 的 connect 实例作中间件使用
|
|
67
69
|
app.use(vite.middlewares);
|
|
70
|
+
// 用于 vite-node 进行服务重载时,先关闭原有服务的端口监听
|
|
71
|
+
if (options?.server && options?.importMetaHot && options.importMetaHot?.on && options.importMetaHot?.dispose) {
|
|
72
|
+
async function killServer() {
|
|
73
|
+
await options.server.close((err) => {
|
|
74
|
+
console.log('vite-plugin-blocklet: Server closed succeed');
|
|
75
|
+
console.error('vite-plugin-blocklet: Failed to close server', err);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
options.importMetaHot.on('vite:beforeFullReload', async () => {
|
|
79
|
+
console.log('vite-plugin-blocklet: Full reload');
|
|
80
|
+
await killServer();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
options.importMetaHot.dispose(async () => {
|
|
84
|
+
console.log('vite-plugin-blocklet: Dispose');
|
|
85
|
+
await killServer();
|
|
86
|
+
});
|
|
87
|
+
}
|
|
68
88
|
return vite;
|
|
69
89
|
}
|
|
70
90
|
}
|