Skip to content

Commit

Permalink
feat(vite-plugin-blocklet): support vite-node hot reload server side …
Browse files Browse the repository at this point in the history
…code (#335)
  • Loading branch information
LancelotLewis authored Jul 10, 2024
1 parent 80adc73 commit a597f92
Show file tree
Hide file tree
Showing 28 changed files with 101 additions and 76 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.8.6 (2024-7-10)

- chore(deps): update deps
- feat(vite-plugin-blocklet): support vite-node hot reload server side code

## 0.8.5 (2024-7-7)

- fix(vite-plugin-blocklet): custom hmr host & port support
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "create-blocklet",
"private": true,
"version": "0.8.5",
"version": "0.8.6",
"description": "",
"keywords": [],
"author": "",
Expand All @@ -17,7 +17,7 @@
},
"dependencies": {
"bumpp": "^9.4.1",
"zx": "^8.1.3"
"zx": "^8.1.4"
},
"devDependencies": {
"simple-git-hooks": "^2.11.1"
Expand Down
4 changes: 2 additions & 2 deletions packages/create-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-blocklet",
"version": "0.8.5",
"version": "0.8.6",
"exports": "./index.js",
"type": "module",
"repository": "git@github.com:blocklet/create-blocklet.git",
Expand Down Expand Up @@ -42,7 +42,7 @@
"prompts": "^2.4.2",
"semver": "^7.6.2",
"terminal-link": "^3.0.0",
"zx": "^8.1.3"
"zx": "^8.1.4"
},
"devDependencies": {
"@arcblock/eslint-config-base": "^0.3.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/templates/express-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"prettier": "^3.3.2",
"rimraf": "^5.0.7",
"simple-git-hooks": "^2.11.1",
"zx": "^8.1.3"
"zx": "^8.1.4"
},
"simple-git-hooks": {
"pre-commit": "npx lint-staged"
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/templates/html-static/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
"bumpp": "^9.4.1",
"prettier": "^3.3.2",
"rimraf": "^5.0.7",
"zx": "^8.1.3"
"zx": "^8.1.4"
}
}
2 changes: 1 addition & 1 deletion packages/create-app/templates/monorepo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"eslint": "^8.57.0",
"prettier": "^3.3.2",
"simple-git-hooks": "^2.11.1",
"zx": "^8.1.3"
"zx": "^8.1.4"
},
"simple-git-hooks": {
"pre-commit": "npx lint-staged"
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/templates/nestjs-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.5.2",
"zx": "^8.1.3"
"zx": "^8.1.4"
},
"simple-git-hooks": {
"pre-commit": "npx lint-staged"
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/templates/nextjs-dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"npm-run-all": "^4.1.5",
"rimraf": "^5.0.7",
"simple-git-hooks": "^2.11.1",
"zx": "^8.1.3"
"zx": "^8.1.4"
},
"simple-git-hooks": {
"pre-commit": "npx lint-staged"
Expand Down
6 changes: 3 additions & 3 deletions packages/create-app/templates/react-dapp-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@
"simple-git-hooks": "^2.11.1",
"ts-node": "^10.9.2",
"typescript": "^5.5.2",
"vite": "^5.3.2",
"vite-plugin-blocklet": "^0.8.5",
"vite": "^5.3.3",
"vite-plugin-blocklet": "^0.8.6",
"vite-plugin-svgr": "^4.2.0",
"zx": "^8.1.3"
"zx": "^8.1.4"
},
"importSort": {
".js, .jsx, .mjs": {
Expand Down
6 changes: 3 additions & 3 deletions packages/create-app/templates/react-dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@
"react-router-dom": "^6.24.0",
"rimraf": "^5.0.7",
"simple-git-hooks": "^2.11.1",
"vite": "^5.3.2",
"vite-plugin-blocklet": "^0.8.5",
"vite": "^5.3.3",
"vite-plugin-blocklet": "^0.8.6",
"vite-plugin-svgr": "^4.2.0",
"zx": "^8.1.3"
"zx": "^8.1.4"
},
"simple-git-hooks": {
"pre-commit": "npx lint-staged"
Expand Down
6 changes: 3 additions & 3 deletions packages/create-app/templates/react-gun-dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@
"react-router-dom": "^6.24.0",
"rimraf": "^5.0.7",
"simple-git-hooks": "^2.11.1",
"vite": "^5.3.2",
"vite-plugin-blocklet": "^0.8.5",
"vite": "^5.3.3",
"vite-plugin-blocklet": "^0.8.6",
"vite-plugin-svgr": "^4.2.0",
"zx": "^8.1.3"
"zx": "^8.1.4"
},
"simple-git-hooks": {
"pre-commit": "npx lint-staged"
Expand Down
6 changes: 3 additions & 3 deletions packages/create-app/templates/react-static/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@
"react-router-dom": "^6.24.0",
"rimraf": "^5.0.7",
"simple-git-hooks": "^2.11.1",
"vite": "^5.3.2",
"vite-plugin-blocklet": "^0.8.5",
"vite": "^5.3.3",
"vite-plugin-blocklet": "^0.8.6",
"vite-plugin-svgr": "^4.2.0",
"zx": "^8.1.3"
"zx": "^8.1.4"
},
"simple-git-hooks": {
"pre-commit": "npx lint-staged"
Expand Down
6 changes: 3 additions & 3 deletions packages/create-app/templates/solidjs-dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
"prettier": "^3.3.2",
"rimraf": "^5.0.7",
"simple-git-hooks": "^2.11.1",
"vite": "^5.3.2",
"vite-plugin-blocklet": "^0.8.5",
"vite": "^5.3.3",
"vite-plugin-blocklet": "^0.8.6",
"vite-plugin-solid": "^2.10.2",
"zx": "^8.1.3"
"zx": "^8.1.4"
},
"dependencies": {
"@arcblock/did-auth": "^1.18.126",
Expand Down
6 changes: 3 additions & 3 deletions packages/create-app/templates/solidjs-static/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
"rimraf": "^5.0.7",
"simple-git-hooks": "^2.11.1",
"solid-js": "^1.8.18",
"vite": "^5.3.2",
"vite-plugin-blocklet": "^0.8.5",
"vite": "^5.3.3",
"vite-plugin-blocklet": "^0.8.6",
"vite-plugin-solid": "^2.10.2",
"zx": "^8.1.3"
"zx": "^8.1.4"
},
"lint-staged": {
"*.{mjs,js,jsx,tsx}": [
Expand Down
6 changes: 3 additions & 3 deletions packages/create-app/templates/svelte-dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
"rimraf": "^5.0.7",
"simple-git-hooks": "^2.11.1",
"svelte": "^4.2.18",
"vite": "^5.3.2",
"vite-plugin-blocklet": "^0.8.5",
"zx": "^8.1.3"
"vite": "^5.3.3",
"vite-plugin-blocklet": "^0.8.6",
"zx": "^8.1.4"
},
"lint-staged": {
"*.{mjs,js,svelte}": [
Expand Down
6 changes: 3 additions & 3 deletions packages/create-app/templates/svelte-static/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
"rimraf": "^5.0.7",
"simple-git-hooks": "^2.11.1",
"svelte": "^4.2.18",
"vite": "^5.3.2",
"vite-plugin-blocklet": "^0.8.5",
"zx": "^8.1.3"
"vite": "^5.3.3",
"vite-plugin-blocklet": "^0.8.6",
"zx": "^8.1.4"
},
"lint-staged": {
"*.{mjs,js,svelte}": [
Expand Down
6 changes: 3 additions & 3 deletions packages/create-app/templates/todo-list-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@
"simple-git-hooks": "^2.11.1",
"ts-node": "^10.9.2",
"typescript": "^5.5.2",
"vite": "^5.3.2",
"vite-plugin-blocklet": "^0.8.5",
"vite": "^5.3.3",
"vite-plugin-blocklet": "^0.8.6",
"vite-plugin-svgr": "^4.2.0",
"zx": "^8.1.3"
"zx": "^8.1.4"
},
"importSort": {
".js, .jsx, .mjs": {
Expand Down
6 changes: 3 additions & 3 deletions packages/create-app/templates/vue-dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@
"prettier": "^3.3.2",
"rimraf": "^5.0.7",
"simple-git-hooks": "^2.11.1",
"vite": "^5.3.2",
"vite-plugin-blocklet": "^0.8.5",
"vite": "^5.3.3",
"vite-plugin-blocklet": "^0.8.6",
"vue": "^3.4.31",
"zx": "^8.1.3"
"zx": "^8.1.4"
},
"lint-staged": {
"*.{mjs,js,vue}": [
Expand Down
6 changes: 3 additions & 3 deletions packages/create-app/templates/vue-static/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
"prettier": "^3.3.2",
"rimraf": "^5.0.7",
"simple-git-hooks": "^2.11.1",
"vite": "^5.3.2",
"vite-plugin-blocklet": "^0.8.5",
"vite": "^5.3.3",
"vite-plugin-blocklet": "^0.8.6",
"vue": "^3.4.31",
"zx": "^8.1.3"
"zx": "^8.1.4"
},
"lint-staged": {
"*.{mjs,js,vue}": [
Expand Down
6 changes: 3 additions & 3 deletions packages/create-app/templates/vue2-dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@
"prettier": "^3.3.2",
"rimraf": "^5.0.7",
"simple-git-hooks": "^2.11.1",
"vite": "^5.3.2",
"vite-plugin-blocklet": "^0.8.5",
"vite": "^5.3.3",
"vite-plugin-blocklet": "^0.8.6",
"vue": "^2.7.16",
"zx": "^8.1.3"
"zx": "^8.1.4"
},
"lint-staged": {
"*.{mjs,js,vue}": [
Expand Down
6 changes: 3 additions & 3 deletions packages/create-app/templates/vue2-static/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
"prettier": "^3.3.2",
"rimraf": "^5.0.7",
"simple-git-hooks": "^2.11.1",
"vite": "^5.3.2",
"vite-plugin-blocklet": "^0.8.5",
"vite": "^5.3.3",
"vite-plugin-blocklet": "^0.8.6",
"vue": "^2.7.16",
"zx": "^8.1.3"
"zx": "^8.1.4"
},
"lint-staged": {
"*.{mjs,js,vue}": [
Expand Down
20 changes: 20 additions & 0 deletions plugins/vite-plugin-blocklet/libs/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const isProduction = process.env.NODE_ENV === 'production' || process.env.ABT_NO
* @param {number} [options.clientPort] - The clientPort for the ws server.
* @param {string} [options.configFile=''] - The path to the config file.
* @param {string} [options.appType='spa'] - The type of the application.
* @param {import('node:http').Server} [options.server] - The http server instance
* @param {object} [options.importMetaHot] - vite import.meta.hot
* @return {Promise<Object>} A promise that resolves to the Vite server object.
*/
export default async function setupClient(app, options = {}) {
Expand Down Expand Up @@ -65,6 +67,24 @@ export default async function setupClient(app, options = {}) {
});
// 将 vite 的 connect 实例作中间件使用
app.use(vite.middlewares);
// 用于 vite-node 进行服务重载时,先关闭原有服务的端口监听
if (options?.server && options?.importMetaHot && options.importMetaHot?.on && options.importMetaHot?.dispose) {
async function killServer() {
await options.server.close((err) => {
console.log('vite-plugin-blocklet: Server closed succeed');
console.error('vite-plugin-blocklet: Failed to close server', err);
});
}
options.importMetaHot.on('vite:beforeFullReload', async () => {
console.log('vite-plugin-blocklet: Full reload');
await killServer();
});

options.importMetaHot.dispose(async () => {
console.log('vite-plugin-blocklet: Dispose');
await killServer();
});
}
return vite;
}
}
2 changes: 1 addition & 1 deletion plugins/vite-plugin-blocklet/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vite-plugin-blocklet",
"type": "module",
"version": "0.8.5",
"version": "0.8.6",
"description": "",
"main": "index.js",
"files": [
Expand Down
4 changes: 2 additions & 2 deletions plugins/vite-plugin-wss-hmr/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vite-plugin-wss-hmr",
"type": "module",
"version": "0.8.5",
"version": "0.8.6",
"description": "",
"main": "index.js",
"exports": {
Expand All @@ -21,6 +21,6 @@
"license": "ISC",
"devDependencies": {
"rollup": "^2.79.1",
"vite": "^5.3.2"
"vite": "^5.3.3"
}
}
Loading

0 comments on commit a597f92

Please sign in to comment.