From 1a8c13adcd6285706885fbe81265558a0f6a7504 Mon Sep 17 00:00:00 2001 From: zhenyuWang <13641039885@163.com> Date: Thu, 24 Nov 2022 16:26:54 +0800 Subject: [PATCH] perf(vue-devtools): optimize debug page --- .../lib/front/{mp-qq => }/app.html | 4 +- .../lib/front/mp-alipay/app.html | 57 ------------------- .../lib/front/mp-alipay/network.js | 8 --- .../lib/front/mp-baidu/app.html | 57 ------------------- .../lib/front/mp-baidu/network.js | 8 --- .../lib/front/mp-kuaishou/app.html | 57 ------------------- .../lib/front/mp-kuaishou/network.js | 8 --- .../lib/front/mp-lark/app.html | 57 ------------------- .../lib/front/mp-lark/network.js | 8 --- .../lib/front/mp-qq/network.js | 8 --- .../lib/front/mp-toutiao/app.html | 57 ------------------- .../lib/front/mp-toutiao/network.js | 8 --- .../lib/front/mp-weixin/app.html | 57 ------------------- .../lib/front/mp-weixin/network.js | 8 --- packages/uni-vue-devtools/lib/front/server.js | 45 ++++----------- packages/uni-vue-devtools/package.json | 1 - packages/uni-vue-devtools/tsconfig.json | 6 +- pnpm-lock.yaml | 2 - 18 files changed, 15 insertions(+), 441 deletions(-) rename packages/uni-vue-devtools/lib/front/{mp-qq => }/app.html (89%) delete mode 100644 packages/uni-vue-devtools/lib/front/mp-alipay/app.html delete mode 100644 packages/uni-vue-devtools/lib/front/mp-alipay/network.js delete mode 100644 packages/uni-vue-devtools/lib/front/mp-baidu/app.html delete mode 100644 packages/uni-vue-devtools/lib/front/mp-baidu/network.js delete mode 100644 packages/uni-vue-devtools/lib/front/mp-kuaishou/app.html delete mode 100644 packages/uni-vue-devtools/lib/front/mp-kuaishou/network.js delete mode 100644 packages/uni-vue-devtools/lib/front/mp-lark/app.html delete mode 100644 packages/uni-vue-devtools/lib/front/mp-lark/network.js delete mode 100644 packages/uni-vue-devtools/lib/front/mp-qq/network.js delete mode 100644 packages/uni-vue-devtools/lib/front/mp-toutiao/app.html delete mode 100644 packages/uni-vue-devtools/lib/front/mp-toutiao/network.js delete mode 100644 packages/uni-vue-devtools/lib/front/mp-weixin/app.html delete mode 100644 packages/uni-vue-devtools/lib/front/mp-weixin/network.js diff --git a/packages/uni-vue-devtools/lib/front/mp-qq/app.html b/packages/uni-vue-devtools/lib/front/app.html similarity index 89% rename from packages/uni-vue-devtools/lib/front/mp-qq/app.html rename to packages/uni-vue-devtools/lib/front/app.html index 0e62503805..78a73f09ee 100644 --- a/packages/uni-vue-devtools/lib/front/mp-qq/app.html +++ b/packages/uni-vue-devtools/lib/front/app.html @@ -2,7 +2,7 @@ - + uni-dev-tools - - -
- -

- Waiting for connection... -

-
-
-
- - - - \ No newline at end of file diff --git a/packages/uni-vue-devtools/lib/front/mp-alipay/network.js b/packages/uni-vue-devtools/lib/front/mp-alipay/network.js deleted file mode 100644 index 90c6cd288b..0000000000 --- a/packages/uni-vue-devtools/lib/front/mp-alipay/network.js +++ /dev/null @@ -1,8 +0,0 @@ - -window.process = { - env: { - HOST: '192.168.12.130', - PORT: '8099', - } -} - \ No newline at end of file diff --git a/packages/uni-vue-devtools/lib/front/mp-baidu/app.html b/packages/uni-vue-devtools/lib/front/mp-baidu/app.html deleted file mode 100644 index ce39b9dacd..0000000000 --- a/packages/uni-vue-devtools/lib/front/mp-baidu/app.html +++ /dev/null @@ -1,57 +0,0 @@ - - - - - - uni-dev-tools - - - -
- -

- Waiting for connection... -

-
-
-
- - - - \ No newline at end of file diff --git a/packages/uni-vue-devtools/lib/front/mp-baidu/network.js b/packages/uni-vue-devtools/lib/front/mp-baidu/network.js deleted file mode 100644 index 52872d5987..0000000000 --- a/packages/uni-vue-devtools/lib/front/mp-baidu/network.js +++ /dev/null @@ -1,8 +0,0 @@ - -window.process = { - env: { - HOST: '192.168.12.130', - PORT: '8100', - } -} - \ No newline at end of file diff --git a/packages/uni-vue-devtools/lib/front/mp-kuaishou/app.html b/packages/uni-vue-devtools/lib/front/mp-kuaishou/app.html deleted file mode 100644 index 49f8d805cc..0000000000 --- a/packages/uni-vue-devtools/lib/front/mp-kuaishou/app.html +++ /dev/null @@ -1,57 +0,0 @@ - - - - - - uni-dev-tools - - - -
- -

- Waiting for connection... -

-
-
-
- - - - \ No newline at end of file diff --git a/packages/uni-vue-devtools/lib/front/mp-kuaishou/network.js b/packages/uni-vue-devtools/lib/front/mp-kuaishou/network.js deleted file mode 100644 index 09e79e2d82..0000000000 --- a/packages/uni-vue-devtools/lib/front/mp-kuaishou/network.js +++ /dev/null @@ -1,8 +0,0 @@ - -window.process = { - env: { - HOST: '192.168.12.130', - PORT: '8098', - } -} - \ No newline at end of file diff --git a/packages/uni-vue-devtools/lib/front/mp-lark/app.html b/packages/uni-vue-devtools/lib/front/mp-lark/app.html deleted file mode 100644 index 6c957541ea..0000000000 --- a/packages/uni-vue-devtools/lib/front/mp-lark/app.html +++ /dev/null @@ -1,57 +0,0 @@ - - - - - - uni-dev-tools - - - -
- -

- Waiting for connection... -

-
-
-
- - - - \ No newline at end of file diff --git a/packages/uni-vue-devtools/lib/front/mp-lark/network.js b/packages/uni-vue-devtools/lib/front/mp-lark/network.js deleted file mode 100644 index 09e79e2d82..0000000000 --- a/packages/uni-vue-devtools/lib/front/mp-lark/network.js +++ /dev/null @@ -1,8 +0,0 @@ - -window.process = { - env: { - HOST: '192.168.12.130', - PORT: '8098', - } -} - \ No newline at end of file diff --git a/packages/uni-vue-devtools/lib/front/mp-qq/network.js b/packages/uni-vue-devtools/lib/front/mp-qq/network.js deleted file mode 100644 index 52872d5987..0000000000 --- a/packages/uni-vue-devtools/lib/front/mp-qq/network.js +++ /dev/null @@ -1,8 +0,0 @@ - -window.process = { - env: { - HOST: '192.168.12.130', - PORT: '8100', - } -} - \ No newline at end of file diff --git a/packages/uni-vue-devtools/lib/front/mp-toutiao/app.html b/packages/uni-vue-devtools/lib/front/mp-toutiao/app.html deleted file mode 100644 index ba27e5a657..0000000000 --- a/packages/uni-vue-devtools/lib/front/mp-toutiao/app.html +++ /dev/null @@ -1,57 +0,0 @@ - - - - - - uni-dev-tools - - - -
- -

- Waiting for connection... -

-
-
-
- - - - \ No newline at end of file diff --git a/packages/uni-vue-devtools/lib/front/mp-toutiao/network.js b/packages/uni-vue-devtools/lib/front/mp-toutiao/network.js deleted file mode 100644 index 90c6cd288b..0000000000 --- a/packages/uni-vue-devtools/lib/front/mp-toutiao/network.js +++ /dev/null @@ -1,8 +0,0 @@ - -window.process = { - env: { - HOST: '192.168.12.130', - PORT: '8099', - } -} - \ No newline at end of file diff --git a/packages/uni-vue-devtools/lib/front/mp-weixin/app.html b/packages/uni-vue-devtools/lib/front/mp-weixin/app.html deleted file mode 100644 index 6256ed4c17..0000000000 --- a/packages/uni-vue-devtools/lib/front/mp-weixin/app.html +++ /dev/null @@ -1,57 +0,0 @@ - - - - - - uni-dev-tools - - - -
- -

- Waiting for connection... -

-
-
-
- - - - \ No newline at end of file diff --git a/packages/uni-vue-devtools/lib/front/mp-weixin/network.js b/packages/uni-vue-devtools/lib/front/mp-weixin/network.js deleted file mode 100644 index 09e79e2d82..0000000000 --- a/packages/uni-vue-devtools/lib/front/mp-weixin/network.js +++ /dev/null @@ -1,8 +0,0 @@ - -window.process = { - env: { - HOST: '192.168.12.130', - PORT: '8098', - } -} - \ No newline at end of file diff --git a/packages/uni-vue-devtools/lib/front/server.js b/packages/uni-vue-devtools/lib/front/server.js index 106c919d17..1c412527b4 100644 --- a/packages/uni-vue-devtools/lib/front/server.js +++ b/packages/uni-vue-devtools/lib/front/server.js @@ -1,3 +1,4 @@ +/* eslint-disable no-restricted-globals */ const _detectPort = require('detect-port'); const os = require('os') const { createServer } = require('http') @@ -51,15 +52,22 @@ function detectPort(port) { } function initFrontServer(socketHost, socketPort, network, devtoolsPort) { - const platform = process.env.UNI_PLATFORM - app.use(express.static(__dirname)) app.get('/', (_, res) => { - res.send(fs.readFileSync(path.resolve(__dirname, `./${platform}/app.html`)).toString()) + res.send(fs.readFileSync(path.resolve(__dirname, `./app.html`)).toString()) }) - writeNetworkFile(platform, socketHost, socketPort) + app.get('/network', (_, res) => { + res.send( + `window.process = { + env: { + HOST: '${socketHost}', + PORT: '${socketPort}', + } + } ` + ) + }) app.listen(devtoolsPort, 'localhost', () => { const colorUrl = (url) => colors.cyan(url.replace(/:(\d+)\//, (_, port) => `:${colors.bold(port)}/`)) @@ -72,35 +80,6 @@ function initFrontServer(socketHost, socketPort, network, devtoolsPort) { } -function writeNetworkFile(platform, HOST, PORT) { - fs.open( - path.resolve(__dirname, `./${platform}/network.js`), - 'w', - (err, fd) => { - if (err) { - console.log(colors.red(err)) - return - } - fs.write( - fd, - ` -window.process = { - env: { - HOST: '${HOST}', - PORT: '${PORT}', - } -} - `, - (err) => { - if (err) { - console.log(colors.red(err)) - } - } - ) - } - ) -} - function initSocketServer(host, port) { const httpServer = createServer(app) const io = new Server(httpServer, { diff --git a/packages/uni-vue-devtools/package.json b/packages/uni-vue-devtools/package.json index 015ed9958d..01ad964921 100644 --- a/packages/uni-vue-devtools/package.json +++ b/packages/uni-vue-devtools/package.json @@ -26,7 +26,6 @@ "detect-port": "^1.5.1", "express": "^4.17.1", "open": "^8.4.0", - "picocolors": "^1.0.0", "socket.io": "^4.4.0" } } diff --git a/packages/uni-vue-devtools/tsconfig.json b/packages/uni-vue-devtools/tsconfig.json index 2ddca0a822..4183e6767d 100644 --- a/packages/uni-vue-devtools/tsconfig.json +++ b/packages/uni-vue-devtools/tsconfig.json @@ -10,9 +10,5 @@ "../global.d.ts", "../shims-node.d.ts", "../shims-uni-app.d.ts" - ], - "baseUrl":".", - "paths": { - "tslib" : ["node_modules/tslib/tslib.d.ts"] - } + ] } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 04e57b4f2a..7ed477f479 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -839,14 +839,12 @@ importers: detect-port: ^1.5.1 express: ^4.17.1 open: ^8.4.0 - picocolors: ^1.0.0 socket.io: ^4.4.0 dependencies: '@dcloudio/uni-cli-shared': link:../uni-cli-shared detect-port: 1.5.1 express: 4.18.2 open: 8.4.0 - picocolors: 1.0.0 socket.io: 4.5.4 packages/uts: -- GitLab