Skip to content

Vue3-插件引入

@types/node类型声明包插件

  • 安装@types/node 类型声明包
JS
yarn add @types/node -D

作用:

是将 Node.js 的类型定义文件安装到 TypeScript 项目中,作为开发依赖(devDependency)添加。这样我们在使用Node.js的标准库模块时可以享受类型检查和代码补全的功能,也就是补全的作用。

unplugin-auto-import自动引入插件

安装引入

☞ 安装插件

js
yarn add unplugin-auto-import -D

配置

☞ 在 vite.config.js 中进行配置

js
plugins: [
  AutoImport({
    imports: [
      'vue', // 自动引入 Vue 函数
      'vue-router', // 自动引入 vue-router 的函数
    ],
    dts: true,  // 生成类型声明文件
  }),
],

确保你的tsconfig.json文件下有如下配置

js
"esModuleInterop": true,

// 放置位置
{
  "compilerOptions": {
    "esModuleInterop": true,
    "moduleResolution": "node",
    "strict": true,
    "jsx": "preserve",
    "lib": ["esnext", "dom"]
  }
}

Released under the MIT License.