Skip to content

Commit 6b33694

Browse files
authored
feat: introducing openInEditorHost option (#72)
1 parent 4dfb3ff commit 6b33694

File tree

6 files changed

+75
-14
lines changed

6 files changed

+75
-14
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ interface VitePluginInspectorOptions {
132132
* WARNING: only set this if you know exactly what it does.
133133
*/
134134
appendTo?: string | RegExp
135+
136+
/**
137+
* Customize openInEditor host (e.g. http://localhost:3000)
138+
* @default false
139+
*/
140+
openInEditorHost?: string | false
135141
}
136142
```
137143

packages/core/README.md

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ export default defineConfig({
7171
```ts
7272
// for Nuxt3
7373
// nuxt.config.ts
74-
7574
import { defineNuxtConfig } from 'nuxt/config'
7675
import Inspector from 'vite-plugin-vue-inspector'
7776

@@ -87,6 +86,7 @@ export default defineNuxtConfig({
8786

8887
### Options
8988

89+
9090
```ts
9191
interface VitePluginInspectorOptions {
9292
/**
@@ -109,8 +109,9 @@ interface VitePluginInspectorOptions {
109109
* examples: control-shift, control-o, control-alt-s meta-x control-meta
110110
* Some keys have native behavior (e.g. alt-s opens history menu on firefox).
111111
* To avoid conflicts or accidentally typing into inputs, modifier only combinations are recommended.
112+
* You can also disable it by setting `false`.
112113
*/
113-
toggleComboKey?: string
114+
toggleComboKey?: string | false
114115

115116
/**
116117
* Toggle button visibility
@@ -131,6 +132,12 @@ interface VitePluginInspectorOptions {
131132
* WARNING: only set this if you know exactly what it does.
132133
*/
133134
appendTo?: string | RegExp
135+
136+
/**
137+
* Customize openInEditor host (e.g. http://localhost:3000)
138+
* @default false
139+
*/
140+
openInEditorHost?: string | false
134141
}
135142
```
136143

@@ -144,12 +151,12 @@ interface VitePluginInspectorOptions {
144151

145152
It uses an **environment variable** named **`VUE_EDITOR`** to specify an IDE application, but if you do not set this variable, it will try to open a common IDE that you have open or installed once it is certified.
146153

147-
For example, if you want it always open VSCode when inspection clicked, set `export VUE_EDITOR=code` in your shell.
154+
For example, if you want it always open VS Code when inspection clicked, set `export VUE_EDITOR=code` in your shell.
148155

149156

150-
### VSCode
157+
### VS Code
151158

152-
- install VSCode command line tools, [see the official docs](https://code.visualstudio.com/docs/setup/mac#_launching-from-the-command-line)
159+
- install VS Code command line tools, [see the official docs](https://code.visualstudio.com/docs/setup/mac#_launching-from-the-command-line)
153160
![install-vscode-cli](./public/install-vscode-cli.png)
154161

155162
- set env to shell, like `.bashrc` or `.zshrc`
@@ -160,6 +167,23 @@ For example, if you want it always open VSCode when inspection clicked, set `exp
160167

161168
<br />
162169

170+
### VS Code with WSL (Windows)
171+
172+
- add the configuration in the `settings.json`
173+
174+
- restart the VS Code (All Windows should be closed to take effect)
175+
176+
```json
177+
{
178+
// other config...
179+
180+
"terminal.integrated.env.linux": {
181+
"EDITOR": "code"
182+
}
183+
}
184+
```
185+
186+
163187
### WebStorm
164188

165189
- just set env with an absolute path to shell, like `.bashrc` or `.zshrc` (only MacOS)

packages/core/src/Overlay.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const protocol = inspectorOptions.serverOptions?.https ? 'https:' : importMetaUr
66
const hostOpts = inspectorOptions.serverOptions?.host
77
const host = hostOpts && hostOpts !== true ? hostOpts : importMetaUrl?.hostname
88
const port = inspectorOptions.serverOptions?.port ?? importMetaUrl?.port
9-
const baseUrl = isClient ? `${protocol}//${host}:${port}` : ''
9+
const baseUrl = isClient ? inspectorOptions.openInEditorHost || `${protocol}//${host}:${port}` : ''
1010
1111
const KEY_DATA = 'data-v-inspector'
1212
const KEY_IGNORE = 'data-v-inspector-ignore'

packages/core/src/index.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import path from 'path'
2-
import { fileURLToPath } from 'url'
3-
import fs from 'fs'
1+
import path from 'node:path'
2+
import { fileURLToPath } from 'node:url'
3+
import fs from 'node:fs'
44
import { bold, dim, green, yellow } from 'kolorist'
55
import { normalizePath } from 'vite'
66
import type { PluginOption, ServerOptions } from 'vite'
@@ -70,6 +70,12 @@ export interface VitePluginInspectorOptions {
7070
* WARNING: only set this if you know exactly what it does.
7171
*/
7272
appendTo?: string | RegExp
73+
74+
/**
75+
* Customize openInEditor host (e.g. http://localhost:3000)
76+
* @default false
77+
*/
78+
openInEditorHost?: string | false
7379
}
7480

7581
const toggleComboKeysMap = {
@@ -94,6 +100,7 @@ export const DEFAULT_INSPECTOR_OPTIONS: VitePluginInspectorOptions = {
94100
toggleButtonVisibility: 'active',
95101
toggleButtonPos: 'top-right',
96102
appendTo: '',
103+
openInEditorHost: false,
97104
} as const
98105

99106
function VitePluginInspector(options: VitePluginInspectorOptions = DEFAULT_INSPECTOR_OPTIONS): PluginOption {

packages/playground/vue3/vite.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default defineConfig({
99
VueJsx(),
1010
Inspector({
1111
enabled: true,
12+
openInEditorHost: "http://127.0.0.1:5173",
1213
toggleButtonVisibility: 'always',
1314
}),
1415
],

packages/unplugin/README.md

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ export default defineConfig({
7171
```ts
7272
// for Nuxt3
7373
// nuxt.config.ts
74-
7574
import { defineNuxtConfig } from 'nuxt/config'
7675
import Inspector from 'vite-plugin-vue-inspector'
7776

@@ -110,8 +109,9 @@ interface VitePluginInspectorOptions {
110109
* examples: control-shift, control-o, control-alt-s meta-x control-meta
111110
* Some keys have native behavior (e.g. alt-s opens history menu on firefox).
112111
* To avoid conflicts or accidentally typing into inputs, modifier only combinations are recommended.
112+
* You can also disable it by setting `false`.
113113
*/
114-
toggleComboKey?: string
114+
toggleComboKey?: string | false
115115

116116
/**
117117
* Toggle button visibility
@@ -132,6 +132,12 @@ interface VitePluginInspectorOptions {
132132
* WARNING: only set this if you know exactly what it does.
133133
*/
134134
appendTo?: string | RegExp
135+
136+
/**
137+
* Customize openInEditor host (e.g. http://localhost:3000)
138+
* @default false
139+
*/
140+
openInEditorHost?: string | false
135141
}
136142
```
137143

@@ -145,12 +151,12 @@ interface VitePluginInspectorOptions {
145151

146152
It uses an **environment variable** named **`VUE_EDITOR`** to specify an IDE application, but if you do not set this variable, it will try to open a common IDE that you have open or installed once it is certified.
147153

148-
For example, if you want it always open VSCode when inspection clicked, set `export VUE_EDITOR=code` in your shell.
154+
For example, if you want it always open VS Code when inspection clicked, set `export VUE_EDITOR=code` in your shell.
149155

150156

151-
### VSCode
157+
### VS Code
152158

153-
- install VSCode command line tools, [see the official docs](https://code.visualstudio.com/docs/setup/mac#_launching-from-the-command-line)
159+
- install VS Code command line tools, [see the official docs](https://code.visualstudio.com/docs/setup/mac#_launching-from-the-command-line)
154160
![install-vscode-cli](./public/install-vscode-cli.png)
155161

156162
- set env to shell, like `.bashrc` or `.zshrc`
@@ -161,6 +167,23 @@ For example, if you want it always open VSCode when inspection clicked, set `exp
161167

162168
<br />
163169

170+
### VS Code with WSL (Windows)
171+
172+
- add the configuration in the `settings.json`
173+
174+
- restart the VS Code (All Windows should be closed to take effect)
175+
176+
```json
177+
{
178+
// other config...
179+
180+
"terminal.integrated.env.linux": {
181+
"EDITOR": "code"
182+
}
183+
}
184+
```
185+
186+
164187
### WebStorm
165188

166189
- just set env with an absolute path to shell, like `.bashrc` or `.zshrc` (only MacOS)

0 commit comments

Comments
 (0)