vite-plugin-blocklet 0.5.1 → 0.5.3

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 CHANGED
@@ -11,7 +11,6 @@ var fs = require('fs');
11
11
  var path = require('path');
12
12
  var YAML = require('yaml');
13
13
  var getPort = require('get-port');
14
- var httpProxyMiddleware = require('http-proxy-middleware');
15
14
 
16
15
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
17
16
 
@@ -46,10 +45,6 @@ function createHmrPlugin({ version = vite.version } = {}) {
46
45
  "const base = __BASE__ || '/';\nlet tmpPort = __HMR_PORT__;\nif (window.blocklet) {\ntmpPort = new URL(window.location.href).port + base;\n}\nconst socketHost = `${__HMR_HOSTNAME__ || location.hostname}${tmpPort ? `:${tmpPort}` : ''}`;"
47
46
  );
48
47
  return replacedCode;
49
- } else if (pureVersion === 3) {
50
- let replacedCode = code;
51
- replacedCode = replacedCode.replace('__HMR_PORT__', 'undefined');
52
- return replacedCode;
53
48
  }
54
49
  }
55
50
  },
@@ -157,25 +152,22 @@ function createMetaPlugin() {
157
152
 
158
153
  const isProduction = process.env.NODE_ENV === 'production' || process.env.ABT_NODE_SERVICE_ENV === 'production';
159
154
 
160
- async function setupClient(app, server, options = {}) {
155
+ async function setupClient(app, options = {}) {
161
156
  if (!isProduction) {
162
- const randomport = await getPort__default["default"]();
163
- const { host = 'localhost', protocol = 'ws', port = randomport } = options;
164
- const hmrPath = `/_vite_websocket_${port}`;
157
+ const { host = '127.0.0.1', protocol = 'ws', port: inputPort } = options;
158
+ const port = await getPort__default["default"]({ port: inputPort });
165
159
  // 以中间件模式创建 Vite 服务器
166
160
  const vite$1 = await vite.createServer({
167
161
  server: {
168
162
  middlewareMode: true,
169
163
  hmr: {
164
+ host,
170
165
  port,
171
- path: hmrPath,
166
+ protocol,
172
167
  },
173
168
  },
174
169
  });
175
170
  // 将 vite 的 connect 实例作中间件使用
176
- const wsProxy = httpProxyMiddleware.createProxyMiddleware(`${protocol}://${host}:${port}`);
177
- app.use(hmrPath, wsProxy);
178
- server.on('upgrade', wsProxy.upgrade);
179
171
  app.use(vite$1.middlewares);
180
172
  }
181
173
  }
package/libs/client.js CHANGED
@@ -1,28 +1,24 @@
1
1
  import getPort from 'get-port';
2
2
  import { createServer } from 'vite';
3
- import { createProxyMiddleware } from 'http-proxy-middleware';
4
3
 
5
4
  const isProduction = process.env.NODE_ENV === 'production' || process.env.ABT_NODE_SERVICE_ENV === 'production';
6
5
 
7
- export default async function setupClient(app, server, options = {}) {
6
+ export default async function setupClient(app, options = {}) {
8
7
  if (!isProduction) {
9
- const randomport = await getPort();
10
- const { host = 'localhost', protocol = 'ws', port = randomport } = options;
11
- const hmrPath = `/_vite_websocket_${port}`;
8
+ const { host = '127.0.0.1', protocol = 'ws', port: inputPort } = options;
9
+ const port = await getPort({ port: inputPort });
12
10
  // 以中间件模式创建 Vite 服务器
13
11
  const vite = await createServer({
14
12
  server: {
15
13
  middlewareMode: true,
16
14
  hmr: {
15
+ host,
17
16
  port,
18
- path: hmrPath,
17
+ protocol,
19
18
  },
20
19
  },
21
20
  });
22
21
  // 将 vite 的 connect 实例作中间件使用
23
- const wsProxy = createProxyMiddleware(`${protocol}://${host}:${port}`);
24
- app.use(hmrPath, wsProxy);
25
- server.on('upgrade', wsProxy.upgrade);
26
22
  app.use(vite.middlewares);
27
23
  }
28
24
  }
package/libs/hmr.js CHANGED
@@ -17,10 +17,6 @@ export default function createHmrPlugin({ version = viteVersion } = {}) {
17
17
  "const base = __BASE__ || '/';\nlet tmpPort = __HMR_PORT__;\nif (window.blocklet) {\ntmpPort = new URL(window.location.href).port + base;\n}\nconst socketHost = `${__HMR_HOSTNAME__ || location.hostname}${tmpPort ? `:${tmpPort}` : ''}`;"
18
18
  );
19
19
  return replacedCode;
20
- } else if (pureVersion === 3) {
21
- let replacedCode = code;
22
- replacedCode = replacedCode.replace('__HMR_PORT__', 'undefined');
23
- return replacedCode;
24
20
  }
25
21
  }
26
22
  },
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-plugin-blocklet",
3
3
  "type": "module",
4
- "version": "0.5.1",
4
+ "version": "0.5.3",
5
5
  "description": "",
6
6
  "main": "index.js",
7
7
  "files": [
@@ -27,11 +27,10 @@
27
27
  "rollup": "^2.79.1"
28
28
  },
29
29
  "dependencies": {
30
- "@arcblock/did": "^1.18.6",
31
- "@ocap/mcrypto": "^1.18.6",
32
- "@ocap/util": "^1.18.6",
30
+ "@arcblock/did": "^1.18.13",
31
+ "@ocap/mcrypto": "^1.18.13",
32
+ "@ocap/util": "^1.18.13",
33
33
  "get-port": "^5.1.1",
34
- "http-proxy-middleware": "^2.0.6",
35
34
  "semver": "^7.3.8",
36
35
  "yaml": "^2.1.3"
37
36
  },