@tomjs/vite-plugin-vscode 2.6.0 → 3.1.0
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/README.md +19 -2
- package/README.zh_CN.md +25 -2
- package/dist/client.global.js +3 -24
- package/dist/index.d.mts +15 -7
- package/dist/index.d.ts +15 -7
- package/dist/index.js +26 -6
- package/dist/index.mjs +27 -7
- package/dist/webview.js +0 -10
- package/dist/webview.mjs +0 -10
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -14,6 +14,7 @@ In development mode, inject the same code of [@tomjs/vscode-extension-webview](h
|
|
|
14
14
|
- Simple configuration, focus on business
|
|
15
15
|
- Support `esm` and `cjs`
|
|
16
16
|
- Support webview `HMR`
|
|
17
|
+
- Support `acquireVsCodeApi` of [@types/vscode-webview](https://www.npmjs.com/package/@types/vscode-webview)
|
|
17
18
|
- Support [Multi-Page App](https://vitejs.dev/guide/build.html#multi-page-app)
|
|
18
19
|
- Supports `vue` and `react` and other [frameworks](https://cn.vitejs.dev/guide/#trying-vite-online) supported by `vite`
|
|
19
20
|
|
|
@@ -221,15 +222,16 @@ const value = await acquireVsCodeApi().getState();
|
|
|
221
222
|
| recommended | `boolean` | `true` | This option is intended to provide recommended default parameters and behavior. |
|
|
222
223
|
| extension | [ExtensionOptions](#ExtensionOptions) | | Configuration options for the vscode extension. |
|
|
223
224
|
| webview | `boolean` \| `string` \| [WebviewOption](#WebviewOption) | `__getWebviewHtml__` | Inject html code |
|
|
225
|
+
| devtools | `boolean` | `true` | Inject script code for [react-devtools](https://github.com/facebook/react/tree/main/packages/react-devtools) or [vue-devtools](https://devtools.vuejs.org/guide/standalone) debugging |
|
|
224
226
|
|
|
225
|
-
|
|
227
|
+
#### Notice
|
|
226
228
|
|
|
227
229
|
The `recommended` option is used to set the default configuration and behavior, which can be used with almost zero configuration. The default is `true`. If you want to customize the configuration, set it to `false`. The following default prerequisites are to use the recommended [project structure](#directory-structure).
|
|
228
230
|
|
|
229
231
|
- The output directory is based on the `build.outDir` parameter of `vite`, and outputs `extension` and `src` to `dist/extension` and `dist/webview` respectively.
|
|
230
232
|
- Other behaviors to be implemented
|
|
231
233
|
|
|
232
|
-
|
|
234
|
+
#### Webview
|
|
233
235
|
|
|
234
236
|
Inject [@tomjs/vscode-extension-webview](https://github.com/tomjs/vscode-extension-webview) into vscode extension code and web client code, so that `webview` can support `HMR` during the development stage.
|
|
235
237
|
|
|
@@ -239,6 +241,13 @@ Inject [@tomjs/vscode-extension-webview](https://github.com/tomjs/vscode-extensi
|
|
|
239
241
|
- vite build
|
|
240
242
|
- extension: Inject `import __getWebviewHtml__ from '@tomjs/vite-plugin-vscode-inject';` above the file that calls the `__getWebviewHtml__` method If is string, will set inject method name. Default is `__getWebviewHtml__`.
|
|
241
243
|
|
|
244
|
+
#### devtools
|
|
245
|
+
|
|
246
|
+
During development, support standalone development tool applications for `react` and `vue`, enabled by default.
|
|
247
|
+
|
|
248
|
+
- `react`: inject `<script src="http://localhost:8097"></script>`, support [react-devtools](https://github.com/facebook/react/tree/main/packages/react-devtools)
|
|
249
|
+
- `vue`: inject `<script src="http://localhost:8098"></script>`, support [vue-devtools](https://devtools.vuejs.org/guide/standalone)
|
|
250
|
+
|
|
242
251
|
### ExtensionOptions
|
|
243
252
|
|
|
244
253
|
Based on [Options](https://paka.dev/npm/tsup) of [tsup](https://tsup.egoist.dev/), some default values are added for ease of use.
|
|
@@ -384,3 +393,11 @@ Open the [examples](./examples) directory, there are `vue` and `react` examples.
|
|
|
384
393
|
- [@tomjs/vscode](https://npmjs.com/package/@tomjs/vscode): Some utilities to simplify the development of [VSCode Extensions](https://marketplace.visualstudio.com/VSCode).
|
|
385
394
|
- [@tomjs/vscode-dev](https://npmjs.com/package/@tomjs/vscode-dev): Some development tools to simplify the development of [vscode extensions](https://marketplace.visualstudio.com/VSCode).
|
|
386
395
|
- [@tomjs/vscode-webview](https://npmjs.com/package/@tomjs/vscode-webview): Optimize the `postMessage` issue between `webview` page and [vscode extensions](https://marketplace.visualstudio.com/VSCode)
|
|
396
|
+
|
|
397
|
+
## Important Notes
|
|
398
|
+
|
|
399
|
+
### v3.0.0
|
|
400
|
+
|
|
401
|
+
**Breaking Updates:**
|
|
402
|
+
|
|
403
|
+
- The simulated `acquireVsCodeApi` is consistent with the `acquireVsCodeApi` of [@types/vscode-webview](https://www.npmjs.com/package/@types/vscode-webview), and `sessionStorage.getItem` and `sessionStorage.setItem` are used to implement `getState` and `setState`.
|
package/README.zh_CN.md
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
- 配置简单,专注业务
|
|
15
15
|
- 支持 `esm`和 `cjs`
|
|
16
16
|
- 支持 webview `HMR`
|
|
17
|
+
- 支持 [@types/vscode-webview](https://www.npmjs.com/package/@types/vscode-webview) 的 `acquireVsCodeApi`
|
|
17
18
|
- 支持[多页面应用](https://cn.vitejs.dev/guide/build.html#multi-page-app)
|
|
18
19
|
- 支持 `vue` 、`react` 等其他 `vite` 支持的[框架](https://cn.vitejs.dev/guide/#trying-vite-online)
|
|
19
20
|
|
|
@@ -225,8 +226,9 @@ const value = await acquireVsCodeApi().getState();
|
|
|
225
226
|
| recommended | `boolean` | `true` | 这个选项是为了提供推荐的默认参数和行为 |
|
|
226
227
|
| extension | [ExtensionOptions](#ExtensionOptions) | | vscode extension 可选配置 |
|
|
227
228
|
| webview | `boolean` \| `string` \| [WebviewOption](#WebviewOption) | `__getWebviewHtml__` | 注入 html 代码 |
|
|
229
|
+
| devtools | `boolean` | `true` | 注入 script 代码用于 [react-devtools](https://github.com/facebook/react/tree/main/packages/react-devtools) 或 [vue-devtools](https://devtools.vuejs.org/guide/standalone) 调试 |
|
|
228
230
|
|
|
229
|
-
|
|
231
|
+
#### Notice
|
|
230
232
|
|
|
231
233
|
`recommended` 选项用于设置默认配置和行为,几乎可以达到零配置使用,默认为 `true` 。如果你要自定义配置,请设置它为`false`。以下默认的前提条件是使用推荐的 [项目结构](#目录结构)。
|
|
232
234
|
|
|
@@ -234,7 +236,7 @@ const value = await acquireVsCodeApi().getState();
|
|
|
234
236
|
|
|
235
237
|
- 其他待实现的行为
|
|
236
238
|
|
|
237
|
-
|
|
239
|
+
#### Webview
|
|
238
240
|
|
|
239
241
|
在 vscode 扩展代码和 web 客户端代码中注入 [@tomjs/vscode-extension-webview](https://github.com/tomjs/vscode-extension-webview),使 `webview` 在开发阶段能够支持 `HMR`。
|
|
240
242
|
|
|
@@ -244,6 +246,13 @@ const value = await acquireVsCodeApi().getState();
|
|
|
244
246
|
- vite build
|
|
245
247
|
- extension: 在调用 `__getWebviewHtml__` 方法的文件上方注入 `import __getWebviewHtml__ from '@tomjs/vite-plugin-vscode-inject';` 如果为字符串,则设置注入方法名,默认为 `__getWebviewHtml__`。
|
|
246
248
|
|
|
249
|
+
#### devtools
|
|
250
|
+
|
|
251
|
+
开发阶段,支持 `react` 和 `vue` 的独立开发工具应用,默认开启。
|
|
252
|
+
|
|
253
|
+
- `react`: 注入 `<script src="http://localhost:8097"></script>`,支持 [react-devtools](https://github.com/facebook/react/tree/main/packages/react-devtools)
|
|
254
|
+
- `vue`: 注入 `<script src="http://localhost:8098"></script>`,支持 [vue-devtools](https://devtools.vuejs.org/guide/standalone)
|
|
255
|
+
|
|
247
256
|
### ExtensionOptions
|
|
248
257
|
|
|
249
258
|
继承自 [tsup](https://tsup.egoist.dev/) 的 [Options](https://paka.dev/npm/tsup),添加了一些默认值,方便使用。
|
|
@@ -291,6 +300,8 @@ const value = await acquireVsCodeApi().getState();
|
|
|
291
300
|
|
|
292
301
|
## Debug
|
|
293
302
|
|
|
303
|
+
### 扩展调试
|
|
304
|
+
|
|
294
305
|
通过 `vscode` 运行 `Debug Extension` 调试,调试工具参考 [官方文档](https://code.visualstudio.com/docs/editor/debugging)
|
|
295
306
|
|
|
296
307
|
`launch.json` 配置如下:
|
|
@@ -367,6 +378,10 @@ const value = await acquireVsCodeApi().getState();
|
|
|
367
378
|
}
|
|
368
379
|
```
|
|
369
380
|
|
|
381
|
+
### 网页调试
|
|
382
|
+
|
|
383
|
+
可以使用 [react-devtools](https://github.com/facebook/react/tree/main/packages/react-devtools) 和 [vue-devtools](https://devtools.vuejs.org/guide/standalone) 的独立应用调试 `webview`
|
|
384
|
+
|
|
370
385
|
## 示例
|
|
371
386
|
|
|
372
387
|
先执行以下命令安装依赖,并生成库文件:
|
|
@@ -387,3 +402,11 @@ pnpm build
|
|
|
387
402
|
- [@tomjs/vscode](https://npmjs.com/package/@tomjs/vscode): 一些实用工具,用于简化 [vscode 扩展](https://marketplace.visualstudio.com/VSCode) 的开发。
|
|
388
403
|
- [@tomjs/vscode-dev](https://npmjs.com/package/@tomjs/vscode-dev): 一些开发工具,用于简化 [vscode 扩展](https://marketplace.visualstudio.com/VSCode) 的开发。
|
|
389
404
|
- [@tomjs/vscode-webview](https://npmjs.com/package/@tomjs/vscode-webview): 优化 `webview` 页面与 [vscode 扩展](https://marketplace.visualstudio.com/VSCode) 的 `postMessage` 问题
|
|
405
|
+
|
|
406
|
+
## 重要说明
|
|
407
|
+
|
|
408
|
+
### v3.0.0
|
|
409
|
+
|
|
410
|
+
**破坏性更新:**
|
|
411
|
+
|
|
412
|
+
- 模拟的 `acquireVsCodeApi` 与 [@types/vscode-webview](https://www.npmjs.com/package/@types/vscode-webview) 的 `acquireVsCodeApi` 保持一致,改用 `sessionStorage.getItem` 和 `sessionStorage.setItem` 来实现 `getState` 和 `setState`。
|
package/dist/client.global.js
CHANGED
|
@@ -35,8 +35,6 @@
|
|
|
35
35
|
document.head.appendChild(defaultStyles);
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
|
-
var GET_STATE_TYPE = "[vscode:client]:getState";
|
|
39
|
-
var SET_STATE_TYPE = "[vscode:client]:setState";
|
|
40
38
|
var POST_MESSAGE_TYPE = "[vscode:client]:postMessage";
|
|
41
39
|
function patchAcquireVsCodeApi() {
|
|
42
40
|
class AcquireVsCodeApi {
|
|
@@ -46,31 +44,12 @@
|
|
|
46
44
|
}
|
|
47
45
|
getState() {
|
|
48
46
|
console.log(TAG, "mock acquireVsCodeApi.getState");
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
window.parent.postMessage({ type: GET_STATE_TYPE }, "*");
|
|
52
|
-
}
|
|
53
|
-
const timeoutId = setTimeout(() => {
|
|
54
|
-
window.removeEventListener("message", receive);
|
|
55
|
-
reject(new Error("Timeout"));
|
|
56
|
-
}, 2e3);
|
|
57
|
-
function receive(e) {
|
|
58
|
-
var _a, _b;
|
|
59
|
-
console.log(e);
|
|
60
|
-
if (!e.origin.startsWith("vscode-webview://") || ((_a = e.data) == null ? void 0 : _a.type) !== GET_STATE_TYPE) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
window.removeEventListener("message", receive);
|
|
64
|
-
clearTimeout(timeoutId);
|
|
65
|
-
resolve((_b = e.data) == null ? void 0 : _b.data);
|
|
66
|
-
}
|
|
67
|
-
window.addEventListener("message", receive);
|
|
68
|
-
post();
|
|
69
|
-
});
|
|
47
|
+
const state = sessionStorage.getItem("vscodeState");
|
|
48
|
+
return state ? JSON.parse(state) : void 0;
|
|
70
49
|
}
|
|
71
50
|
setState(newState) {
|
|
72
51
|
console.log(TAG, "mock acquireVsCodeApi.setState:", newState);
|
|
73
|
-
|
|
52
|
+
sessionStorage.setItem("vscodeState", JSON.stringify(newState));
|
|
74
53
|
return newState;
|
|
75
54
|
}
|
|
76
55
|
}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PluginOption } from 'vite';
|
|
2
2
|
import { Options } from 'tsup';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -56,11 +56,11 @@ interface PluginOptions {
|
|
|
56
56
|
/**
|
|
57
57
|
* Inject [@tomjs/vscode-extension-webview](https://github.com/tomjs/vscode-extension-webview) into vscode extension code and web client code, so that webview can support HMR during the development stage.
|
|
58
58
|
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
59
|
+
* - vite serve
|
|
60
|
+
* - extension: Inject `import __getWebviewHtml__ from '@tomjs/vscode-extension-webview';` above the file that calls the `__getWebviewHtml__` method
|
|
61
|
+
* - web: Add `<script>` tag to index.html and inject `@tomjs/vscode-extension-webview/client` code
|
|
62
|
+
* - vite build
|
|
63
|
+
* - extension: Inject `import __getWebviewHtml__ from '@tomjs/vite-plugin-vscode-inject';` above the file that calls the `__getWebviewHtml__` method
|
|
64
64
|
*
|
|
65
65
|
* If is string, will set inject method name. Default is '__getWebviewHtml__'.
|
|
66
66
|
*
|
|
@@ -88,8 +88,16 @@ interface PluginOptions {
|
|
|
88
88
|
* extension vite config.
|
|
89
89
|
*/
|
|
90
90
|
extension?: ExtensionOptions;
|
|
91
|
+
/**
|
|
92
|
+
* Whether to enable devtools. Inject `<script src="http://localhost:<devtools-port>"></script>` into webview client . Default is true.
|
|
93
|
+
* - true:
|
|
94
|
+
* - react: inject `<script src="http://localhost:8097"></script>`
|
|
95
|
+
* - vue: inject `<script src="http://localhost:8098"></script>`
|
|
96
|
+
* @default true
|
|
97
|
+
*/
|
|
98
|
+
devtools?: boolean;
|
|
91
99
|
}
|
|
92
100
|
|
|
93
|
-
declare function useVSCodePlugin(options?: PluginOptions):
|
|
101
|
+
declare function useVSCodePlugin(options?: PluginOptions): PluginOption;
|
|
94
102
|
|
|
95
103
|
export { ExtensionOptions, PluginOptions, WebviewOption, useVSCodePlugin as default, useVSCodePlugin };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PluginOption } from 'vite';
|
|
2
2
|
import { Options } from 'tsup';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -56,11 +56,11 @@ interface PluginOptions {
|
|
|
56
56
|
/**
|
|
57
57
|
* Inject [@tomjs/vscode-extension-webview](https://github.com/tomjs/vscode-extension-webview) into vscode extension code and web client code, so that webview can support HMR during the development stage.
|
|
58
58
|
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
59
|
+
* - vite serve
|
|
60
|
+
* - extension: Inject `import __getWebviewHtml__ from '@tomjs/vscode-extension-webview';` above the file that calls the `__getWebviewHtml__` method
|
|
61
|
+
* - web: Add `<script>` tag to index.html and inject `@tomjs/vscode-extension-webview/client` code
|
|
62
|
+
* - vite build
|
|
63
|
+
* - extension: Inject `import __getWebviewHtml__ from '@tomjs/vite-plugin-vscode-inject';` above the file that calls the `__getWebviewHtml__` method
|
|
64
64
|
*
|
|
65
65
|
* If is string, will set inject method name. Default is '__getWebviewHtml__'.
|
|
66
66
|
*
|
|
@@ -88,8 +88,16 @@ interface PluginOptions {
|
|
|
88
88
|
* extension vite config.
|
|
89
89
|
*/
|
|
90
90
|
extension?: ExtensionOptions;
|
|
91
|
+
/**
|
|
92
|
+
* Whether to enable devtools. Inject `<script src="http://localhost:<devtools-port>"></script>` into webview client . Default is true.
|
|
93
|
+
* - true:
|
|
94
|
+
* - react: inject `<script src="http://localhost:8097"></script>`
|
|
95
|
+
* - vue: inject `<script src="http://localhost:8098"></script>`
|
|
96
|
+
* @default true
|
|
97
|
+
*/
|
|
98
|
+
devtools?: boolean;
|
|
91
99
|
}
|
|
92
100
|
|
|
93
|
-
declare function useVSCodePlugin(options?: PluginOptions):
|
|
101
|
+
declare function useVSCodePlugin(options?: PluginOptions): PluginOption;
|
|
94
102
|
|
|
95
103
|
export { ExtensionOptions, PluginOptions, WebviewOption, useVSCodePlugin as default, useVSCodePlugin };
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,6 @@ var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
|
|
|
3
3
|
var _os = require('os'); var _os2 = _interopRequireDefault(_os);
|
|
4
4
|
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
5
5
|
var _process = require('process');
|
|
6
|
-
var _lodashclonedeep = require('lodash.clonedeep'); var _lodashclonedeep2 = _interopRequireDefault(_lodashclonedeep);
|
|
7
6
|
var _lodashmerge = require('lodash.merge'); var _lodashmerge2 = _interopRequireDefault(_lodashmerge);
|
|
8
7
|
var _nodehtmlparser = require('node-html-parser');
|
|
9
8
|
var _tsup = require('tsup');
|
|
@@ -119,7 +118,7 @@ function preMergeOptions(options) {
|
|
|
119
118
|
skipNodeModulesBundle: isDev
|
|
120
119
|
}
|
|
121
120
|
},
|
|
122
|
-
|
|
121
|
+
options
|
|
123
122
|
);
|
|
124
123
|
const opt = opts.extension || {};
|
|
125
124
|
["entry", "format"].forEach((prop) => {
|
|
@@ -255,7 +254,7 @@ function useVSCodePlugin(options) {
|
|
|
255
254
|
if (opts.webview) {
|
|
256
255
|
devWebviewClient = _node.readFileSync.call(void 0, _path2.default.join(__dirname, "client.global.js"));
|
|
257
256
|
}
|
|
258
|
-
let
|
|
257
|
+
let resolvedConfig;
|
|
259
258
|
const prodHtmlCache = {};
|
|
260
259
|
return [
|
|
261
260
|
{
|
|
@@ -264,6 +263,9 @@ function useVSCodePlugin(options) {
|
|
|
264
263
|
config(config) {
|
|
265
264
|
return handleConfig(config);
|
|
266
265
|
},
|
|
266
|
+
configResolved(config) {
|
|
267
|
+
resolvedConfig = config;
|
|
268
|
+
},
|
|
267
269
|
configureServer(server) {
|
|
268
270
|
var _a;
|
|
269
271
|
if (!server || !server.httpServer) {
|
|
@@ -319,6 +321,24 @@ function useVSCodePlugin(options) {
|
|
|
319
321
|
if (!opts.webview) {
|
|
320
322
|
return html;
|
|
321
323
|
}
|
|
324
|
+
if (_nullishCoalesce(opts.devtools, () => ( true))) {
|
|
325
|
+
let port;
|
|
326
|
+
if (resolvedConfig.plugins.find(
|
|
327
|
+
(s) => ["vite:react-refresh", "vite:react-swc"].includes(s.name)
|
|
328
|
+
)) {
|
|
329
|
+
port = 8097;
|
|
330
|
+
} else if (resolvedConfig.plugins.find((s) => ["vite:vue", "vite:vue2"].includes(s.name))) {
|
|
331
|
+
port = 8098;
|
|
332
|
+
}
|
|
333
|
+
if (port) {
|
|
334
|
+
html = html.replace(
|
|
335
|
+
/<head>/i,
|
|
336
|
+
`<head><script src="http://localhost:${port}"></script>`
|
|
337
|
+
);
|
|
338
|
+
} else {
|
|
339
|
+
logger.warn("Only support react or vue!");
|
|
340
|
+
}
|
|
341
|
+
}
|
|
322
342
|
return html.replace(/<\/title>/i, `</title><script>${devWebviewClient}</script>`);
|
|
323
343
|
}
|
|
324
344
|
},
|
|
@@ -330,7 +350,7 @@ function useVSCodePlugin(options) {
|
|
|
330
350
|
return handleConfig(config);
|
|
331
351
|
},
|
|
332
352
|
configResolved(config) {
|
|
333
|
-
|
|
353
|
+
resolvedConfig = config;
|
|
334
354
|
},
|
|
335
355
|
transformIndexHtml(html, ctx) {
|
|
336
356
|
var _a;
|
|
@@ -346,12 +366,12 @@ function useVSCodePlugin(options) {
|
|
|
346
366
|
if (webview) {
|
|
347
367
|
webviewPath = genProdWebviewCode(prodHtmlCache, webview);
|
|
348
368
|
}
|
|
349
|
-
let outDir =
|
|
369
|
+
let outDir = resolvedConfig.build.outDir.replace(_process.cwd.call(void 0, ), "").replaceAll("\\", "/");
|
|
350
370
|
if (outDir.startsWith("/")) {
|
|
351
371
|
outDir = outDir.substring(1);
|
|
352
372
|
}
|
|
353
373
|
const env = {
|
|
354
|
-
NODE_ENV:
|
|
374
|
+
NODE_ENV: resolvedConfig.mode || "production",
|
|
355
375
|
VITE_WEBVIEW_DIST: outDir
|
|
356
376
|
};
|
|
357
377
|
logger.info("extension build start");
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// node_modules/.pnpm/tsup@7.2.0_@swc+core@1.
|
|
1
|
+
// node_modules/.pnpm/tsup@7.2.0_@swc+core@1.7.26_postcss@8.4.32_typescript@5.3.3/node_modules/tsup/assets/esm_shims.js
|
|
2
2
|
import { fileURLToPath } from "url";
|
|
3
3
|
import path from "path";
|
|
4
4
|
var getFilename = () => fileURLToPath(import.meta.url);
|
|
@@ -10,7 +10,6 @@ import fs from "fs";
|
|
|
10
10
|
import os from "os";
|
|
11
11
|
import path2 from "path";
|
|
12
12
|
import { cwd } from "process";
|
|
13
|
-
import cloneDeep from "lodash.clonedeep";
|
|
14
13
|
import merge from "lodash.merge";
|
|
15
14
|
import { parse as htmlParser } from "node-html-parser";
|
|
16
15
|
import { build as tsupBuild } from "tsup";
|
|
@@ -126,7 +125,7 @@ function preMergeOptions(options) {
|
|
|
126
125
|
skipNodeModulesBundle: isDev
|
|
127
126
|
}
|
|
128
127
|
},
|
|
129
|
-
|
|
128
|
+
options
|
|
130
129
|
);
|
|
131
130
|
const opt = opts.extension || {};
|
|
132
131
|
["entry", "format"].forEach((prop) => {
|
|
@@ -262,7 +261,7 @@ function useVSCodePlugin(options) {
|
|
|
262
261
|
if (opts.webview) {
|
|
263
262
|
devWebviewClient = readFileSync(path2.join(__dirname, "client.global.js"));
|
|
264
263
|
}
|
|
265
|
-
let
|
|
264
|
+
let resolvedConfig;
|
|
266
265
|
const prodHtmlCache = {};
|
|
267
266
|
return [
|
|
268
267
|
{
|
|
@@ -271,6 +270,9 @@ function useVSCodePlugin(options) {
|
|
|
271
270
|
config(config) {
|
|
272
271
|
return handleConfig(config);
|
|
273
272
|
},
|
|
273
|
+
configResolved(config) {
|
|
274
|
+
resolvedConfig = config;
|
|
275
|
+
},
|
|
274
276
|
configureServer(server) {
|
|
275
277
|
var _a;
|
|
276
278
|
if (!server || !server.httpServer) {
|
|
@@ -326,6 +328,24 @@ function useVSCodePlugin(options) {
|
|
|
326
328
|
if (!opts.webview) {
|
|
327
329
|
return html;
|
|
328
330
|
}
|
|
331
|
+
if (opts.devtools ?? true) {
|
|
332
|
+
let port;
|
|
333
|
+
if (resolvedConfig.plugins.find(
|
|
334
|
+
(s) => ["vite:react-refresh", "vite:react-swc"].includes(s.name)
|
|
335
|
+
)) {
|
|
336
|
+
port = 8097;
|
|
337
|
+
} else if (resolvedConfig.plugins.find((s) => ["vite:vue", "vite:vue2"].includes(s.name))) {
|
|
338
|
+
port = 8098;
|
|
339
|
+
}
|
|
340
|
+
if (port) {
|
|
341
|
+
html = html.replace(
|
|
342
|
+
/<head>/i,
|
|
343
|
+
`<head><script src="http://localhost:${port}"></script>`
|
|
344
|
+
);
|
|
345
|
+
} else {
|
|
346
|
+
logger.warn("Only support react or vue!");
|
|
347
|
+
}
|
|
348
|
+
}
|
|
329
349
|
return html.replace(/<\/title>/i, `</title><script>${devWebviewClient}</script>`);
|
|
330
350
|
}
|
|
331
351
|
},
|
|
@@ -337,7 +357,7 @@ function useVSCodePlugin(options) {
|
|
|
337
357
|
return handleConfig(config);
|
|
338
358
|
},
|
|
339
359
|
configResolved(config) {
|
|
340
|
-
|
|
360
|
+
resolvedConfig = config;
|
|
341
361
|
},
|
|
342
362
|
transformIndexHtml(html, ctx) {
|
|
343
363
|
var _a;
|
|
@@ -353,12 +373,12 @@ function useVSCodePlugin(options) {
|
|
|
353
373
|
if (webview) {
|
|
354
374
|
webviewPath = genProdWebviewCode(prodHtmlCache, webview);
|
|
355
375
|
}
|
|
356
|
-
let outDir =
|
|
376
|
+
let outDir = resolvedConfig.build.outDir.replace(cwd(), "").replaceAll("\\", "/");
|
|
357
377
|
if (outDir.startsWith("/")) {
|
|
358
378
|
outDir = outDir.substring(1);
|
|
359
379
|
}
|
|
360
380
|
const env = {
|
|
361
|
-
NODE_ENV:
|
|
381
|
+
NODE_ENV: resolvedConfig.mode || "production",
|
|
362
382
|
VITE_WEBVIEW_DIST: outDir
|
|
363
383
|
};
|
|
364
384
|
logger.info("extension build start");
|
package/dist/webview.js
CHANGED
|
@@ -102,16 +102,6 @@ var template_default = `<!doctype html>
|
|
|
102
102
|
console.log(TAG + ' received:', e.data);
|
|
103
103
|
if (type === '[vscode:client]:postMessage') {
|
|
104
104
|
getApi().postMessage(data);
|
|
105
|
-
} else if (type === '[vscode:client]:getState') {
|
|
106
|
-
iframe.contentWindow.postMessage(
|
|
107
|
-
{
|
|
108
|
-
type: '[vscode:client]:getState',
|
|
109
|
-
data: getApi().getState(),
|
|
110
|
-
},
|
|
111
|
-
'*',
|
|
112
|
-
);
|
|
113
|
-
} else if (type === '[vscode:client]:setState') {
|
|
114
|
-
getApi().setState(data);
|
|
115
105
|
}
|
|
116
106
|
}
|
|
117
107
|
}
|
package/dist/webview.mjs
CHANGED
|
@@ -102,16 +102,6 @@ var template_default = `<!doctype html>
|
|
|
102
102
|
console.log(TAG + ' received:', e.data);
|
|
103
103
|
if (type === '[vscode:client]:postMessage') {
|
|
104
104
|
getApi().postMessage(data);
|
|
105
|
-
} else if (type === '[vscode:client]:getState') {
|
|
106
|
-
iframe.contentWindow.postMessage(
|
|
107
|
-
{
|
|
108
|
-
type: '[vscode:client]:getState',
|
|
109
|
-
data: getApi().getState(),
|
|
110
|
-
},
|
|
111
|
-
'*',
|
|
112
|
-
);
|
|
113
|
-
} else if (type === '[vscode:client]:setState') {
|
|
114
|
-
getApi().setState(data);
|
|
115
105
|
}
|
|
116
106
|
}
|
|
117
107
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tomjs/vite-plugin-vscode",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Use vue/react to develop 'vscode extension webview', supporting esm/cjs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vite",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"@tomjs/tsconfig": "^1.3.0",
|
|
80
80
|
"@types/lodash.clonedeep": "^4.5.9",
|
|
81
81
|
"@types/lodash.merge": "^4.6.9",
|
|
82
|
-
"@types/node": "
|
|
82
|
+
"@types/node": "18.19.55",
|
|
83
83
|
"cross-env": "^7.0.3",
|
|
84
84
|
"eslint": "^8.56.0",
|
|
85
85
|
"husky": "^8.0.3",
|
|
@@ -89,7 +89,8 @@
|
|
|
89
89
|
"rimraf": "^5.0.5",
|
|
90
90
|
"stylelint": "^16.1.0",
|
|
91
91
|
"tsx": "^4.7.0",
|
|
92
|
-
"typescript": "~5.3.3"
|
|
92
|
+
"typescript": "~5.3.3",
|
|
93
|
+
"vite": "5.4.8"
|
|
93
94
|
},
|
|
94
95
|
"peerDependencies": {
|
|
95
96
|
"vite": ">=2"
|