Skip to content

make appendTo accept an array #126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ A vite plugin which provides the ability that to jump to the local IDE when you

```bash

# vite-plugin-vue-inspector
# vite-plugin-vue-inspector

pnpm install vite-plugin-vue-inspector -D

Expand Down Expand Up @@ -133,7 +133,7 @@ interface VitePluginInspectorOptions {
*
* WARNING: only set this if you know exactly what it does.
*/
appendTo?: string | RegExp
appendTo?: string | RegExp | (string | RegExp)[]

/**
* Customize openInEditor host (e.g. http://localhost:3000)
Expand Down Expand Up @@ -216,7 +216,7 @@ For example, if you want it always open VS Code when inspection clicked, set `ex
- install VS Code command line tools, [see the official docs](https://code.visualstudio.com/docs/setup/mac#_launching-from-the-command-line)
![install-vscode-cli](./public/install-vscode-cli.png)

- set env to shell, like `.bashrc` or `.zshrc`
- set env to shell, like `.bashrc` or `.zshrc`

```bash
export LAUNCH_EDITOR=code
Expand All @@ -242,9 +242,9 @@ For example, if you want it always open VS Code when inspection clicked, set `ex
```


### WebStorm
### WebStorm

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

```bash
export LAUNCH_EDITOR='/Applications/WebStorm.app/Contents/MacOS/webstorm'
Expand All @@ -254,7 +254,7 @@ For example, if you want it always open VS Code when inspection clicked, set `ex

- install WebStorm command line tools

- then set env to shell, like `.bashrc` or `.zshrc`
- then set env to shell, like `.bashrc` or `.zshrc`

```bash
export LAUNCH_EDITOR=webstorm
Expand Down
12 changes: 6 additions & 6 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ A vite plugin which provides the ability that to jump to the local IDE when you

```bash

# vite-plugin-vue-inspector
# vite-plugin-vue-inspector

pnpm install vite-plugin-vue-inspector -D

Expand Down Expand Up @@ -133,7 +133,7 @@ interface VitePluginInspectorOptions {
*
* WARNING: only set this if you know exactly what it does.
*/
appendTo?: string | RegExp
appendTo?: string | RegExp | (string | RegExp)[]

/**
* Customize openInEditor host (e.g. http://localhost:3000)
Expand Down Expand Up @@ -216,7 +216,7 @@ For example, if you want it always open VS Code when inspection clicked, set `ex
- install VS Code command line tools, [see the official docs](https://code.visualstudio.com/docs/setup/mac#_launching-from-the-command-line)
![install-vscode-cli](./public/install-vscode-cli.png)

- set env to shell, like `.bashrc` or `.zshrc`
- set env to shell, like `.bashrc` or `.zshrc`

```bash
export LAUNCH_EDITOR=code
Expand All @@ -242,9 +242,9 @@ For example, if you want it always open VS Code when inspection clicked, set `ex
```


### WebStorm
### WebStorm

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

```bash
export LAUNCH_EDITOR='/Applications/WebStorm.app/Contents/MacOS/webstorm'
Expand All @@ -254,7 +254,7 @@ For example, if you want it always open VS Code when inspection clicked, set `ex

- install WebStorm command line tools

- then set env to shell, like `.bashrc` or `.zshrc`
- then set env to shell, like `.bashrc` or `.zshrc`

```bash
export LAUNCH_EDITOR=webstorm
Expand Down
13 changes: 9 additions & 4 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export interface VitePluginInspectorOptions {
*
* WARNING: only set this if you know exactly what it does.
*/
appendTo?: string | RegExp
appendTo?: string | RegExp | (string | RegExp)[]

/**
* Customize openInEditor host (e.g. http://localhost:3000)
Expand Down Expand Up @@ -159,6 +159,8 @@ function VitePluginInspector(options: VitePluginInspectorOptions = DEFAULT_INSPE
cleanHtml = vue === 3, // Only enabled for Vue 3 by default
} = normalizedOptions

const hasAppendTo = () => appendTo || (Array.isArray(appendTo) && appendTo.length > 0)

if (normalizedOptions.launchEditor)
process.env.LAUNCH_EDITOR = normalizedOptions.launchEditor

Expand Down Expand Up @@ -205,11 +207,14 @@ function VitePluginInspector(options: VitePluginInspectorOptions = DEFAULT_INSPE
if (isJsx || isTpl)
return compileSFCTemplate({ code, id: filename, type: isJsx ? 'jsx' : 'template' })

if (!appendTo)
if (!hasAppendTo())
return

if ((typeof appendTo === 'string' && filename.endsWith(appendTo))
|| (appendTo instanceof RegExp && appendTo.test(filename)))
|| (appendTo instanceof RegExp && appendTo.test(filename))
|| (Array.isArray(appendTo) && appendTo.some(path =>
typeof path === 'string' ? filename.endsWith(path) : path.test(filename)
)))
return { code: `${code}\nimport 'virtual:vue-inspector-path:load.js'` }
},
configureServer(server) {
Expand All @@ -223,7 +228,7 @@ function VitePluginInspector(options: VitePluginInspectorOptions = DEFAULT_INSPE
})
},
transformIndexHtml(html) {
if (appendTo)
if (!hasAppendTo())
return
return {
html,
Expand Down
12 changes: 6 additions & 6 deletions packages/unplugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ A vite plugin which provides the ability that to jump to the local IDE when you

```bash

# vite-plugin-vue-inspector
# vite-plugin-vue-inspector

pnpm install vite-plugin-vue-inspector -D

Expand Down Expand Up @@ -133,7 +133,7 @@ interface VitePluginInspectorOptions {
*
* WARNING: only set this if you know exactly what it does.
*/
appendTo?: string | RegExp
appendTo?: string | RegExp | (string | RegExp)[]

/**
* Customize openInEditor host (e.g. http://localhost:3000)
Expand Down Expand Up @@ -217,7 +217,7 @@ For example, if you want it always open VS Code when inspection clicked, set `ex
- install VS Code command line tools, [see the official docs](https://code.visualstudio.com/docs/setup/mac#_launching-from-the-command-line)
![install-vscode-cli](./public/install-vscode-cli.png)

- set env to shell, like `.bashrc` or `.zshrc`
- set env to shell, like `.bashrc` or `.zshrc`

```bash
export LAUNCH_EDITOR=code
Expand All @@ -243,9 +243,9 @@ For example, if you want it always open VS Code when inspection clicked, set `ex
```


### WebStorm
### WebStorm

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

```bash
export LAUNCH_EDITOR='/Applications/WebStorm.app/Contents/MacOS/webstorm'
Expand All @@ -255,7 +255,7 @@ For example, if you want it always open VS Code when inspection clicked, set `ex

- install WebStorm command line tools

- then set env to shell, like `.bashrc` or `.zshrc`
- then set env to shell, like `.bashrc` or `.zshrc`

```bash
export LAUNCH_EDITOR=webstorm
Expand Down