A vite plugin which provides the ability that to jump to the local IDE when you click the element of browser automatically. It supports Vue2 & 3 & SSR.
# pnpm
pnpm install vite-plugin-vue-inspector -D
# yarn
yarn add vite-plugin-vue-inspector -D
# npm
npm install vite-plugin-vue-inspector -D
// for Vue2
import { defineConfig } from "vite"
import { createVuePlugin } from "vite-plugin-vue2"
import Inspector from "vite-plugin-vue-inspector"
export default defineConfig({
plugins: [
createVuePlugin(),
Inspector({
vue: 2
}),
],
})
// for Vue3
import { defineConfig } from "vite"
import Vue from "@vitejs/plugin-vue"
import Inspector from "vite-plugin-vue-inspector"
export default defineConfig({
plugins: [Vue(), Inspector()],
})
// for Nuxt3
// nuxt.config.ts
import { defineNuxtConfig } from 'nuxt'
import Inspector from "vite-plugin-vue-inspector"
export default defineNuxtConfig({
vite: {
plugins:[
Inspector({
appendTo: "entry.mjs"
})
]
}
})
interface VitePluginInspectorOptions {
/**
* Vue version
* @default 3
*/
vue?: 2 | 3
/**
* Default enable state
* @default false
*/
enabled?: boolean
/**
* Define a combo key to toggle inspector
* @default 'control-shift' on windows, 'meta-shift' on other os
*
* any number of modifiers `control` `shift` `alt` `meta` followed by zero or one regular key, separated by -
* examples: control-shift, control-o, control-alt-s meta-x control-meta
* Some keys have native behavior (e.g. alt-s opens history menu on firefox).
* To avoid conflicts or accidentally typing into inputs, modifier only combinations are recommended.
*/
toggleComboKey?: string
/**
* Toggle button visibility
* @default 'active'
*/
toggleButtonVisibility?: "always" | "active" | "never"
/**
* Toggle button display position
* @default top-right
*/
toggleButtonPos?: "top-right" | "top-left" | "bottom-right" | "bottom-left"
/**
* append an import to the module id ending with `appendTo` instead of adding a script into body
* useful for frameworks that do not support trannsformIndexHtml hook (e.g. Nuxt3)
*
* WARNING: only set this if you know exactly what it does.
*/
appendTo?: string
}
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.
For example, if you want it always open VSCode when inspection clicked, set export VUE_EDITOR=code
in your shell.
-
install VSCode command line tools, see the official docs
-
set env to shell, like
.bashrc
or.zshrc
export VUE_EDITOR=code
-
just set env with an absolute path to shell, like
.bashrc
or.zshrc
(only MacOS)export VUE_EDITOR='/Applications/WebStorm.app/Contents/MacOS/webstorm'
OR
-
install WebStorm command line tools
-
then set env to shell, like
.bashrc
or.zshrc
export VUE_EDITOR=webstorm
Yes! you can also use vim if you want, just set env to shell
export VUE_EDITOR=vim
- [BREAKING CHANGE] From v1.0,
enabled
option default value changed fromtrue
tofalse
. - It only work in develop mode .
- It does not currently support
Template Engine (e.g. pug)
.
This project is inspired by react-dev-inspector .
Partially implementation is inspired by vite-plugin-svelte-inspector .
[Chinese] 点击页面元素,这个Vite插件帮我打开了Vue组件