@tomjs/vite-plugin-vscode 3.0.0 → 3.1.1
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 +27 -4
- package/dist/index.mjs +27 -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,8 +254,9 @@ 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
|
+
let devtoolsFlag = false;
|
|
259
260
|
return [
|
|
260
261
|
{
|
|
261
262
|
name: "@tomjs:vscode",
|
|
@@ -263,6 +264,9 @@ function useVSCodePlugin(options) {
|
|
|
263
264
|
config(config) {
|
|
264
265
|
return handleConfig(config);
|
|
265
266
|
},
|
|
267
|
+
configResolved(config) {
|
|
268
|
+
resolvedConfig = config;
|
|
269
|
+
},
|
|
266
270
|
configureServer(server) {
|
|
267
271
|
var _a;
|
|
268
272
|
if (!server || !server.httpServer) {
|
|
@@ -318,6 +322,25 @@ function useVSCodePlugin(options) {
|
|
|
318
322
|
if (!opts.webview) {
|
|
319
323
|
return html;
|
|
320
324
|
}
|
|
325
|
+
if (_nullishCoalesce(opts.devtools, () => ( true))) {
|
|
326
|
+
let port;
|
|
327
|
+
if (resolvedConfig.plugins.find(
|
|
328
|
+
(s) => ["vite:react-refresh", "vite:react-swc"].includes(s.name)
|
|
329
|
+
)) {
|
|
330
|
+
port = 8097;
|
|
331
|
+
} else if (resolvedConfig.plugins.find((s) => ["vite:vue", "vite:vue2"].includes(s.name))) {
|
|
332
|
+
port = 8098;
|
|
333
|
+
}
|
|
334
|
+
if (port) {
|
|
335
|
+
html = html.replace(
|
|
336
|
+
/<head>/i,
|
|
337
|
+
`<head><script src="http://localhost:${port}"></script>`
|
|
338
|
+
);
|
|
339
|
+
} else if (!devtoolsFlag) {
|
|
340
|
+
devtoolsFlag = true;
|
|
341
|
+
logger.warn("Only support react-devtools and vue-devtools!");
|
|
342
|
+
}
|
|
343
|
+
}
|
|
321
344
|
return html.replace(/<\/title>/i, `</title><script>${devWebviewClient}</script>`);
|
|
322
345
|
}
|
|
323
346
|
},
|
|
@@ -329,7 +352,7 @@ function useVSCodePlugin(options) {
|
|
|
329
352
|
return handleConfig(config);
|
|
330
353
|
},
|
|
331
354
|
configResolved(config) {
|
|
332
|
-
|
|
355
|
+
resolvedConfig = config;
|
|
333
356
|
},
|
|
334
357
|
transformIndexHtml(html, ctx) {
|
|
335
358
|
var _a;
|
|
@@ -345,12 +368,12 @@ function useVSCodePlugin(options) {
|
|
|
345
368
|
if (webview) {
|
|
346
369
|
webviewPath = genProdWebviewCode(prodHtmlCache, webview);
|
|
347
370
|
}
|
|
348
|
-
let outDir =
|
|
371
|
+
let outDir = resolvedConfig.build.outDir.replace(_process.cwd.call(void 0, ), "").replaceAll("\\", "/");
|
|
349
372
|
if (outDir.startsWith("/")) {
|
|
350
373
|
outDir = outDir.substring(1);
|
|
351
374
|
}
|
|
352
375
|
const env = {
|
|
353
|
-
NODE_ENV:
|
|
376
|
+
NODE_ENV: resolvedConfig.mode || "production",
|
|
354
377
|
VITE_WEBVIEW_DIST: outDir
|
|
355
378
|
};
|
|
356
379
|
logger.info("extension build start");
|
package/dist/index.mjs
CHANGED
|
@@ -261,8 +261,9 @@ 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
|
+
let devtoolsFlag = false;
|
|
266
267
|
return [
|
|
267
268
|
{
|
|
268
269
|
name: "@tomjs:vscode",
|
|
@@ -270,6 +271,9 @@ function useVSCodePlugin(options) {
|
|
|
270
271
|
config(config) {
|
|
271
272
|
return handleConfig(config);
|
|
272
273
|
},
|
|
274
|
+
configResolved(config) {
|
|
275
|
+
resolvedConfig = config;
|
|
276
|
+
},
|
|
273
277
|
configureServer(server) {
|
|
274
278
|
var _a;
|
|
275
279
|
if (!server || !server.httpServer) {
|
|
@@ -325,6 +329,25 @@ function useVSCodePlugin(options) {
|
|
|
325
329
|
if (!opts.webview) {
|
|
326
330
|
return html;
|
|
327
331
|
}
|
|
332
|
+
if (opts.devtools ?? true) {
|
|
333
|
+
let port;
|
|
334
|
+
if (resolvedConfig.plugins.find(
|
|
335
|
+
(s) => ["vite:react-refresh", "vite:react-swc"].includes(s.name)
|
|
336
|
+
)) {
|
|
337
|
+
port = 8097;
|
|
338
|
+
} else if (resolvedConfig.plugins.find((s) => ["vite:vue", "vite:vue2"].includes(s.name))) {
|
|
339
|
+
port = 8098;
|
|
340
|
+
}
|
|
341
|
+
if (port) {
|
|
342
|
+
html = html.replace(
|
|
343
|
+
/<head>/i,
|
|
344
|
+
`<head><script src="http://localhost:${port}"></script>`
|
|
345
|
+
);
|
|
346
|
+
} else if (!devtoolsFlag) {
|
|
347
|
+
devtoolsFlag = true;
|
|
348
|
+
logger.warn("Only support react-devtools and vue-devtools!");
|
|
349
|
+
}
|
|
350
|
+
}
|
|
328
351
|
return html.replace(/<\/title>/i, `</title><script>${devWebviewClient}</script>`);
|
|
329
352
|
}
|
|
330
353
|
},
|
|
@@ -336,7 +359,7 @@ function useVSCodePlugin(options) {
|
|
|
336
359
|
return handleConfig(config);
|
|
337
360
|
},
|
|
338
361
|
configResolved(config) {
|
|
339
|
-
|
|
362
|
+
resolvedConfig = config;
|
|
340
363
|
},
|
|
341
364
|
transformIndexHtml(html, ctx) {
|
|
342
365
|
var _a;
|
|
@@ -352,12 +375,12 @@ function useVSCodePlugin(options) {
|
|
|
352
375
|
if (webview) {
|
|
353
376
|
webviewPath = genProdWebviewCode(prodHtmlCache, webview);
|
|
354
377
|
}
|
|
355
|
-
let outDir =
|
|
378
|
+
let outDir = resolvedConfig.build.outDir.replace(cwd(), "").replaceAll("\\", "/");
|
|
356
379
|
if (outDir.startsWith("/")) {
|
|
357
380
|
outDir = outDir.substring(1);
|
|
358
381
|
}
|
|
359
382
|
const env = {
|
|
360
|
-
NODE_ENV:
|
|
383
|
+
NODE_ENV: resolvedConfig.mode || "production",
|
|
361
384
|
VITE_WEBVIEW_DIST: outDir
|
|
362
385
|
};
|
|
363
386
|
logger.info("extension build start");
|