diff --git a/README.md b/README.md index 9bfaf49..84a41f4 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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) @@ -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 @@ -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' @@ -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 diff --git a/packages/core/README.md b/packages/core/README.md index 9bfaf49..84a41f4 100644 --- a/packages/core/README.md +++ b/packages/core/README.md @@ -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 @@ -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) @@ -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 @@ -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' @@ -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 diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index ac0ab2f..cdf7778 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -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) @@ -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 @@ -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) { @@ -223,7 +228,7 @@ function VitePluginInspector(options: VitePluginInspectorOptions = DEFAULT_INSPE }) }, transformIndexHtml(html) { - if (appendTo) + if (!hasAppendTo()) return return { html, diff --git a/packages/unplugin/README.md b/packages/unplugin/README.md index a609b3e..c0ba892 100644 --- a/packages/unplugin/README.md +++ b/packages/unplugin/README.md @@ -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 @@ -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) @@ -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 @@ -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' @@ -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