@tomjs/vite-plugin-vscode 3.0.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 +10 -2
- package/README.zh_CN.md +16 -2
- package/dist/index.d.mts +13 -5
- package/dist/index.d.ts +13 -5
- package/dist/index.js +25 -4
- package/dist/index.mjs +25 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -222,15 +222,16 @@ const value = await acquireVsCodeApi().getState();
|
|
|
222
222
|
| recommended | `boolean` | `true` | This option is intended to provide recommended default parameters and behavior. |
|
|
223
223
|
| extension | [ExtensionOptions](#ExtensionOptions) | | Configuration options for the vscode extension. |
|
|
224
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 |
|
|
225
226
|
|
|
226
|
-
|
|
227
|
+
#### Notice
|
|
227
228
|
|
|
228
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).
|
|
229
230
|
|
|
230
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.
|
|
231
232
|
- Other behaviors to be implemented
|
|
232
233
|
|
|
233
|
-
|
|
234
|
+
#### Webview
|
|
234
235
|
|
|
235
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.
|
|
236
237
|
|
|
@@ -240,6 +241,13 @@ Inject [@tomjs/vscode-extension-webview](https://github.com/tomjs/vscode-extensi
|
|
|
240
241
|
- vite build
|
|
241
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__`.
|
|
242
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
|
+
|
|
243
251
|
### ExtensionOptions
|
|
244
252
|
|
|
245
253
|
Based on [Options](https://paka.dev/npm/tsup) of [tsup](https://tsup.egoist.dev/), some default values are added for ease of use.
|
package/README.zh_CN.md
CHANGED
|
@@ -226,8 +226,9 @@ const value = await acquireVsCodeApi().getState();
|
|
|
226
226
|
| recommended | `boolean` | `true` | 这个选项是为了提供推荐的默认参数和行为 |
|
|
227
227
|
| extension | [ExtensionOptions](#ExtensionOptions) | | vscode extension 可选配置 |
|
|
228
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) 调试 |
|
|
229
230
|
|
|
230
|
-
|
|
231
|
+
#### Notice
|
|
231
232
|
|
|
232
233
|
`recommended` 选项用于设置默认配置和行为,几乎可以达到零配置使用,默认为 `true` 。如果你要自定义配置,请设置它为`false`。以下默认的前提条件是使用推荐的 [项目结构](#目录结构)。
|
|
233
234
|
|
|
@@ -235,7 +236,7 @@ const value = await acquireVsCodeApi().getState();
|
|
|
235
236
|
|
|
236
237
|
- 其他待实现的行为
|
|
237
238
|
|
|
238
|
-
|
|
239
|
+
#### Webview
|
|
239
240
|
|
|
240
241
|
在 vscode 扩展代码和 web 客户端代码中注入 [@tomjs/vscode-extension-webview](https://github.com/tomjs/vscode-extension-webview),使 `webview` 在开发阶段能够支持 `HMR`。
|
|
241
242
|
|
|
@@ -245,6 +246,13 @@ const value = await acquireVsCodeApi().getState();
|
|
|
245
246
|
- vite build
|
|
246
247
|
- extension: 在调用 `__getWebviewHtml__` 方法的文件上方注入 `import __getWebviewHtml__ from '@tomjs/vite-plugin-vscode-inject';` 如果为字符串,则设置注入方法名,默认为 `__getWebviewHtml__`。
|
|
247
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
|
+
|
|
248
256
|
### ExtensionOptions
|
|
249
257
|
|
|
250
258
|
继承自 [tsup](https://tsup.egoist.dev/) 的 [Options](https://paka.dev/npm/tsup),添加了一些默认值,方便使用。
|
|
@@ -292,6 +300,8 @@ const value = await acquireVsCodeApi().getState();
|
|
|
292
300
|
|
|
293
301
|
## Debug
|
|
294
302
|
|
|
303
|
+
### 扩展调试
|
|
304
|
+
|
|
295
305
|
通过 `vscode` 运行 `Debug Extension` 调试,调试工具参考 [官方文档](https://code.visualstudio.com/docs/editor/debugging)
|
|
296
306
|
|
|
297
307
|
`launch.json` 配置如下:
|
|
@@ -368,6 +378,10 @@ const value = await acquireVsCodeApi().getState();
|
|
|
368
378
|
}
|
|
369
379
|
```
|
|
370
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
|
+
|
|
371
385
|
## 示例
|
|
372
386
|
|
|
373
387
|
先执行以下命令安装依赖,并生成库文件:
|
package/dist/index.d.mts
CHANGED
|
@@ -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,6 +88,14 @@ 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
101
|
declare function useVSCodePlugin(options?: PluginOptions): PluginOption;
|
package/dist/index.d.ts
CHANGED
|
@@ -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,6 +88,14 @@ 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
101
|
declare function useVSCodePlugin(options?: PluginOptions): PluginOption;
|
package/dist/index.js
CHANGED
|
@@ -254,7 +254,7 @@ function useVSCodePlugin(options) {
|
|
|
254
254
|
if (opts.webview) {
|
|
255
255
|
devWebviewClient = _node.readFileSync.call(void 0, _path2.default.join(__dirname, "client.global.js"));
|
|
256
256
|
}
|
|
257
|
-
let
|
|
257
|
+
let resolvedConfig;
|
|
258
258
|
const prodHtmlCache = {};
|
|
259
259
|
return [
|
|
260
260
|
{
|
|
@@ -263,6 +263,9 @@ function useVSCodePlugin(options) {
|
|
|
263
263
|
config(config) {
|
|
264
264
|
return handleConfig(config);
|
|
265
265
|
},
|
|
266
|
+
configResolved(config) {
|
|
267
|
+
resolvedConfig = config;
|
|
268
|
+
},
|
|
266
269
|
configureServer(server) {
|
|
267
270
|
var _a;
|
|
268
271
|
if (!server || !server.httpServer) {
|
|
@@ -318,6 +321,24 @@ function useVSCodePlugin(options) {
|
|
|
318
321
|
if (!opts.webview) {
|
|
319
322
|
return html;
|
|
320
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
|
+
}
|
|
321
342
|
return html.replace(/<\/title>/i, `</title><script>${devWebviewClient}</script>`);
|
|
322
343
|
}
|
|
323
344
|
},
|
|
@@ -329,7 +350,7 @@ function useVSCodePlugin(options) {
|
|
|
329
350
|
return handleConfig(config);
|
|
330
351
|
},
|
|
331
352
|
configResolved(config) {
|
|
332
|
-
|
|
353
|
+
resolvedConfig = config;
|
|
333
354
|
},
|
|
334
355
|
transformIndexHtml(html, ctx) {
|
|
335
356
|
var _a;
|
|
@@ -345,12 +366,12 @@ function useVSCodePlugin(options) {
|
|
|
345
366
|
if (webview) {
|
|
346
367
|
webviewPath = genProdWebviewCode(prodHtmlCache, webview);
|
|
347
368
|
}
|
|
348
|
-
let outDir =
|
|
369
|
+
let outDir = resolvedConfig.build.outDir.replace(_process.cwd.call(void 0, ), "").replaceAll("\\", "/");
|
|
349
370
|
if (outDir.startsWith("/")) {
|
|
350
371
|
outDir = outDir.substring(1);
|
|
351
372
|
}
|
|
352
373
|
const env = {
|
|
353
|
-
NODE_ENV:
|
|
374
|
+
NODE_ENV: resolvedConfig.mode || "production",
|
|
354
375
|
VITE_WEBVIEW_DIST: outDir
|
|
355
376
|
};
|
|
356
377
|
logger.info("extension build start");
|
package/dist/index.mjs
CHANGED
|
@@ -261,7 +261,7 @@ function useVSCodePlugin(options) {
|
|
|
261
261
|
if (opts.webview) {
|
|
262
262
|
devWebviewClient = readFileSync(path2.join(__dirname, "client.global.js"));
|
|
263
263
|
}
|
|
264
|
-
let
|
|
264
|
+
let resolvedConfig;
|
|
265
265
|
const prodHtmlCache = {};
|
|
266
266
|
return [
|
|
267
267
|
{
|
|
@@ -270,6 +270,9 @@ function useVSCodePlugin(options) {
|
|
|
270
270
|
config(config) {
|
|
271
271
|
return handleConfig(config);
|
|
272
272
|
},
|
|
273
|
+
configResolved(config) {
|
|
274
|
+
resolvedConfig = config;
|
|
275
|
+
},
|
|
273
276
|
configureServer(server) {
|
|
274
277
|
var _a;
|
|
275
278
|
if (!server || !server.httpServer) {
|
|
@@ -325,6 +328,24 @@ function useVSCodePlugin(options) {
|
|
|
325
328
|
if (!opts.webview) {
|
|
326
329
|
return html;
|
|
327
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
|
+
}
|
|
328
349
|
return html.replace(/<\/title>/i, `</title><script>${devWebviewClient}</script>`);
|
|
329
350
|
}
|
|
330
351
|
},
|
|
@@ -336,7 +357,7 @@ function useVSCodePlugin(options) {
|
|
|
336
357
|
return handleConfig(config);
|
|
337
358
|
},
|
|
338
359
|
configResolved(config) {
|
|
339
|
-
|
|
360
|
+
resolvedConfig = config;
|
|
340
361
|
},
|
|
341
362
|
transformIndexHtml(html, ctx) {
|
|
342
363
|
var _a;
|
|
@@ -352,12 +373,12 @@ function useVSCodePlugin(options) {
|
|
|
352
373
|
if (webview) {
|
|
353
374
|
webviewPath = genProdWebviewCode(prodHtmlCache, webview);
|
|
354
375
|
}
|
|
355
|
-
let outDir =
|
|
376
|
+
let outDir = resolvedConfig.build.outDir.replace(cwd(), "").replaceAll("\\", "/");
|
|
356
377
|
if (outDir.startsWith("/")) {
|
|
357
378
|
outDir = outDir.substring(1);
|
|
358
379
|
}
|
|
359
380
|
const env = {
|
|
360
|
-
NODE_ENV:
|
|
381
|
+
NODE_ENV: resolvedConfig.mode || "production",
|
|
361
382
|
VITE_WEBVIEW_DIST: outDir
|
|
362
383
|
};
|
|
363
384
|
logger.info("extension build start");
|