Vite 中文文档 Vite 中文文档
指南
GitHub (opens new window)
指南
GitHub (opens new window)
  • vite

    • 指引
    • 为什么选 Vite
    • 开始
    • 功能
    • 命令行界面
    • 使用插件
    • 依赖预构建
    • 静态资源处理
    • 构建生产版本
    • 部署静态站点
    • 环境变量和模式
    • 服务端渲染
    • 后端集成
    • 与其他工具比较
    • 故障排除
    • 从 v3 迁移
  • API

  • 配置参考

  • vite

  • API

  • 配置参考

vite-plugin-vue-inspector

📖 Introduction


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.

vite-plugin-vue-inspector

📦 Installation


  1. ``` shell
  2. # vite-plugin-vue-inspector

  3. pnpm install vite-plugin-vue-inspector -D

  4. # unplugin-vue-inspector

  5. pnpm install unplugin-vue-inspector -D

  6. ```

🦄 Usage


Configuration Vite


  1. ``` ts
  2. // for Vue2

  3. import { defineConfig, } from 'vite'
  4. import { createVuePlugin, } from 'vite-plugin-vue2'
  5. import Inspector from 'unplugin-vue-inspector/vite' // OR vite-plugin-vue-inspector

  6. export default defineConfig({
  7.   plugins: [
  8.     createVuePlugin(),
  9.     Inspector({
  10.       vue: 2
  11.     }),
  12.   ],
  13. })
  14. ```

  1. ``` ts
  2. // for Vue3

  3. import { defineConfig } from 'vite'
  4. import Vue from '@vitejs/plugin-vue'
  5. import Inspector from 'unplugin-vue-inspector/vite' // OR vite-plugin-vue-inspector

  6. export default defineConfig({
  7.   plugins: [Vue(), Inspector()],
  8. })
  9. ```

  1. ``` ts
  2. // for Nuxt3
  3. // nuxt.config.ts
  4. import { defineNuxtConfig } from 'nuxt/config'
  5. import Inspector from 'vite-plugin-vue-inspector'

  6. export default defineNuxtConfig({
  7.   modules: [
  8.     ['unplugin-vue-inspector/nuxt', {
  9.       enabled: true,
  10.       toggleButtonVisibility: 'always',
  11.     }],
  12.   ],
  13. })
  14. ```

Options


  1. ``` ts
  2. interface VitePluginInspectorOptions {
  3.   /**
  4.   * Vue version
  5.   * @default 3
  6.   */
  7.   vue?: 2 | 3

  8.   /**
  9.   * Default enable state
  10.   * @default false
  11.   */
  12.   enabled?: boolean

  13.   /**
  14.   * Define a combo key to toggle inspector
  15.   * @default 'control-shift' on windows, 'meta-shift' on other os
  16.   *
  17.   * any number of modifiers `control` `shift` `alt` `meta` followed by zero or one regular key, separated by -
  18.   * examples: control-shift, control-o, control-alt-s  meta-x control-meta
  19.   * Some keys have native behavior (e.g. alt-s opens history menu on firefox).
  20.   * To avoid conflicts or accidentally typing into inputs, modifier only combinations are recommended.
  21.   * You can also disable it by setting `false`.
  22.   */
  23.   toggleComboKey?: string | false

  24.   /**
  25.   * Toggle button visibility
  26.   * @default 'active'
  27.   */
  28.   toggleButtonVisibility?: 'always' | 'active' | 'never'

  29.   /**
  30.   * Toggle button display position
  31.   * @default top-right
  32.   */
  33.   toggleButtonPos?: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left'

  34.   /**
  35.   * append an import to the module id ending with `appendTo` instead of adding a script into body
  36.   * useful for frameworks that do not support trannsformIndexHtml hook (e.g. Nuxt3)
  37.   *
  38.   * WARNING: only set this if you know exactly what it does.
  39.   */
  40.   appendTo?: string | RegExp
  41. }
  42. ```

Example


Vue2
Vue3
Nuxt3

🔌  Configuration IDE / Editor


It uses an environment variablenamed 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.

VSCode


install VSCode command line tools, see the official docs install-vscode-cli

set env to shell, like .bashrc or .zshrc

  1. ``` shell
  2. export VUE_EDITOR=code
  3. ```

WebStorm


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

  1. ``` shell
  2. export VUE_EDITOR='/Applications/WebStorm.app/Contents/MacOS/webstorm'
  3. ```

OR

install WebStorm command line tools

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

  1. ``` shell
  2. export VUE_EDITOR=webstorm
  3. ```

Vim


Yes! you can also use vim if you want, just set env to shell

  1. ``` shell
  2. export VUE_EDITOR=vim
  3. ```

💡 Notice


[BREAKING CHANGE] From v1.0, enabled option default value changed from true to false.
It only work in develop mode .
It does not currently support Template Engine (e.g. pug).

👨‍💻 Programmatic Usage


You can also use control inspector programmatically, by accessing the __VUE_INSPECTOR__ global variable.

  1. ``` ts
  2. import type { VueInspectorClient } from 'vite-plugin-vue-inspector'

  3. const inspector: VueInspectorClient = window.__VUE_INSPECTOR__

  4. if (inspector) {
  5.   // enable inspector
  6.   inspector.enable()
  7.   // or
  8.   inspector.disable()
  9. }
  10. ```

🌸 Credits


This project is inspired by react-dev-inspector.

Partially implementation is inspired by vite-plugin-svelte-inspector.

🤖️ Analysis of Theory


[Chinese] 点击页面元素,这个Vite插件帮我打开了Vue组件

📄 License


MIT LICENSE
Last Updated: 2023-05-23 11:11:51