当前位置: 首页 > article >正文

.vscode文件夹详解

在使用 Visual Studio Code (VSCode) 进行开发时,配置 .vscode 文件夹可以显著提高开发效率和代码质量。.vscode 文件夹通常包含一些配置文件,如 settings.jsonlaunch.jsontasks.json 等,用于自定义编辑器的行为、调试设置、任务自动化等。以下是详细的配置指南:

1. 创建 .vscode 文件夹

首先,在你的项目根目录下创建一个 .vscode 文件夹:

mkdir .vscode

2. 配置 settings.json

settings.json 文件用于配置 VSCode 的编辑器设置,这些设置仅适用于当前项目。

示例 settings.json

{
  "editor.tabSize": 2,
  "editor.insertSpaces": true,
  "editor.formatOnSave": true,
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  },
  "files.autoSave": "onFocusChange",
  "files.exclude": {
    "**/.git": true,
    "**/.DS_Store": true,
    "**/node_modules": true,
    "**/dist": true
  },
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    "typescript",
    "typescriptreact"
  ],
  "eslint.options": {
    "extensions": [
      ".js",
      ".jsx",
      ".ts",
      ".tsx"
    ]
  },
  "typescript.tsdk": "node_modules/typescript/lib",
  "prettier.requireConfig": true,
  "prettier.configFile": ".prettierrc",
  "prettier.useEditorConfig": false,
  "prettier.semi": false,
  "prettier.singleQuote": true,
  "prettier.printWidth": 80,
  "prettier.tabWidth": 2,
  "prettier.trailingComma": "all",
  "prettier.bracketSpacing": true,
  "prettier.arrowParens": "always",
  "prettier.endOfLine": "auto",
  "eslint.alwaysShowStatus": true,
  "eslint.packageManager": "npm",
  "eslint.experimental.useFlatConfig": true,
  "eslint.workingDirectories": [
    "./"
  ],
  "eslint.probe": [
    "src"
  ],
  "eslint.enable": true,
  "eslint.run": "onType",
  "eslint.quiet": true,
  "eslint.debug": false,
  "eslint.packageManager": "npm",
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    "typescript",
    "typescriptreact"
  ],
  "eslint.options": {
    "extensions": [
      ".js",
      ".jsx",
      ".ts",
      ".tsx"
    ]
  },
  "eslint.packageManager": "npm",
  "eslint.experimental.useFlatConfig": true,
  "eslint.workingDirectories": [
    "./"
  ],
  "eslint.probe": [
    "src"
  ],
  "eslint.enable": true,
  "eslint.run": "onType",
  "eslint.quiet": true,
  "eslint.debug": false
}

3. 配置 launch.json

launch.json 文件用于配置调试设置。

示例 launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Debug Vite",
      "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/vite",
      "args": ["--open"],
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen",
      "skipFiles": ["<node_internals>/**"]
    },
    {
      "type": "node",
      "request": "launch",
      "name": "Debug Production Build",
      "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/vite",
      "args": ["build"],
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen",
      "skipFiles": ["<node_internals>/**"]
    }
  ]
}

4. 配置 tasks.json

tasks.json 文件用于配置自动化任务。

示例 tasks.json

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Build Vite",
      "type": "shell",
      "command": "npm",
      "args": ["run", "build"],
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "problemMatcher": ["$tsc"]
    },
    {
      "label": "Serve Vite",
      "type": "shell",
      "command": "npm",
      "args": ["run", "dev"],
      "group": {
        "kind": "test",
        "isDefault": true
      },
      "problemMatcher": ["$tsc"]
    }
  ]
}

5. 配置 extensions.json

extensions.json 文件用于推荐项目所需的扩展。

示例 extensions.json:

{
  "recommendations": [
    "esbenp.prettier-vscode",
    "dbaeumer.vscode-eslint",
    "ms-vscode.vscode-typescript-next",
    "msjsdiag.vscode-react-native",
    "christian-kohler.path-intellisense",
    "bradlc.vscode-tailwindcss"
  ]
}

总结

通过配置 .vscode 文件夹中的 settings.jsonlaunch.jsontasks.jsonextensions.json,你可以显著提高 VSCode 的开发体验。这些配置文件帮助你管理编辑器设置、调试设置、自动化任务和推荐扩展,确保项目的一致性和代码质量。


http://www.kler.cn/a/542785.html

相关文章:

  • 基于 PyTorch 的树叶分类任务:从数据准备到模型训练与测试
  • Java、Go、Rust、Node.js 的内存占比及优缺点分析
  • 129,【2】buuctf [BJDCTF2020]EzPHP
  • 学习 URL 传参中哪些字符是支持的,哪些是不支持的
  • 【Vue中BUG解决】npm error path git
  • 《DeepSeek大模型的微调和部署案例实操课程》
  • 安装OpenJDK21(linux、macos)
  • Response 和 Request 介绍
  • 7、Python面试题解析:== 与 is,id函数详解
  • C34.【C++ Cont】STL库的双端队列
  • 基于 openEuler 构建 LVS-DR 群集
  • 【ESP32】ESP-IDF开发 | WiFi开发 | HTTP服务器
  • Python基于 Flask 创建简单Web服务并接收文件
  • 头条百度批量采集软件说明文档
  • 2021版小程序开发5——小程序项目开发实践(2)-完
  • Harmony OS和Android 区别
  • 实现限制同一个账号最多只能在3个客户端(有电脑、手机等)登录(附关键源码)
  • C/C++混合读入cin与scanf问题
  • Go1.24 strings包增加的新方法
  • java安全中的类加载
  • 【Apache Paimon】-- 作为一名小白,如何系统地学习 Apache paimon?
  • Unity使用iTextSharp导出PDF-05页面事件
  • RESTful API 和 WebSocket 的区别
  • BootstrapBlazor Table组件 使用的注入 数据服务 实现类:使用 EF Core
  • Spring Cloud 07 - 分布式链路追踪APM
  • Acwing-基础算法课笔记之基础算法(差分)