VSCode配置格式化工具(Prettier/Vetur/ESLint)和jsconfig.json
VSCode配置格式化工具(Prettier/Vetur/ESLint)
网上很多配置,有的过时了, 有的很杂, 自己看了下文档,简单配置了以下, 顺便记录下来。
准备
用vue-cli
建好项目之后,在VSCode安装插件
ESLint
document,Prettier - Code formatter
document, Vetur
document。
cli install
Launch VS Code Quick Open (Ctrl+P)
ext install esbenp.prettier-vscode
配置
.eslintrc.js
使用vue-cli默认生产的就行
新建一个.prettierrc.js
需要什么配置, 自己对文档改
module.exports = {trailingComma: 'es5',printWidth: 100,tabWidth: 2,useTabs: false,semi: false,singleQuote: true,jsxSingleQuote: true,bracketSpacing: true,jsxBracketSameLine: true,arrowParens: "avoid"
}
.eslintrc.js
使用默认的
.eslintignore
可以配置ignore文件
/public/
/dist/
/node_modules/
/src/icons/svg/
/mock/
VSCode的配置settings.json
注意:
The old eslint.autoFixOnSave setting is now deprecated and can safely be removed.
{"workbench.iconTheme": "vscode-icons","files.autoSave": "afterDelay","editor.fontSize": 16,"editor.mouseWheelZoom": true,"editor.suggest.snippetsPreventQuickSuggestions": false,"liveServer.settings.donotShowInfoMsg": true,"workbench.colorTheme": "Material","terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe","editor.tabSize": 2,"editor.tabCompletion": "on",// 下面这几个, 怎么配看文档"editor.defaultFormatter": "esbenp.prettier-vscode","eslint.enable": true,"editor.codeActionsOnSave": {"source.fixAll": false,"source.fixAll.eslint": true //保存自动修复, eslint.autoFixOnSave已废弃}}
如果要配置js-beautify之类的,自己看下文档, 我就不配那么多东西了, 合适够用就好了。
配置script命令
"scripts": {"serve": "vue-cli-service serve","build": "vue-cli-service build","lint": "vue-cli-service lint", //自带的修复"lint-check": "eslint --ext .js,.vue src", // 检查"lint-fix": "eslint --fix --ext .js,.vue src" // 修复},
运行yarn lint-check/fix
可以检查/修复,yarn lint
修复会有修复文件的提示
配置jsconfig.json
参考vertur
路径映射:如用@引入模块会有路径提示
import module from '@/components/module'
jsconfig.json
{"compilerOptions": {"experimentalDecorators": true,"baseUrl": "./","paths": {"components/*": ["src/components/*"],"@/*": ["src/*"]}},"exclude": ["node_modules"],"include": ["src/*"]
}
或者使用tsconfig.json
配置常用代码片段
在VSCode’文件’->‘首选项’->‘用户代码片段’,新建代码片段
defaultSinppets.code-snippets.json
{// Place your 全局 snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and // description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope // is left empty or omitted, the snippet gets applied to all languages. The prefix is what is // used to trigger the snippet and the body will be expanded and inserted. Possible variables are: // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. // Placeholders with the same ids are connected.// Example:// "Print to console": {// "scope": "javascript,typescript",// "prefix": "log",// "body": [// "console.log('$1');",// "$2"// ],// "description": "Log output to console"// }"Print to console": {"scope": "javascript,typescript","prefix": "clg","body": ["console.log('$1')","$2"],"description": "Log output to console"},"Print to dir": {"scope": "javascript,typescript","prefix": "cd","body": ["console.dir('$1')","$2"],"description": "Log output to dir"}
}
希望对你有帮助, 有问题请留言
VSCode配置格式化工具(Prettier/Vetur/ESLint)和jsconfig.json相关推荐
- vscode找不到config_vscode中的 jsconfig.json
什么是jsconfig.json? 目录中存在jsconfig.json文件表示该目录是JavaScript项目的根目录.jsconfig.json文件指定根文件和JavaScript语言服务提供的功 ...
- Vscode配置Vue插件Vetur自动补全和Eslint校验,正在保存“index.vue”: 从 “‘ESLint‘, ‘Vetur‘“ (configure)中获取代码操作
出现这个问题,主要原因是vetur插件自己升级了,我真服了... 问题描述:一直都是这个提示,然后文件保存不了,然后也无法格式化和代码提示 经过一番调教之后,发现通过降级vetur插件搞定了,降级操作 ...
- vscode的格式化工具:eslint 、 prettier、editorconfig 和 vetur
文章目录 eslint--代码检查工具 eslint的作用 eslint的配置 第一步配置IDE的eslint环境 第二步:配置项目中的eslint 下载对应的包 vite集成eslint Eslin ...
- vscode配置ESLint+Prettier - Code formatter+Vetur
首先是安装ESLint+prettier+vetur: vscode 搜索安装即可,然后是注意package是否有这些: 没有的话npm安装. 之后就是配置这个文件: module.exports = ...
- VSCode Eslint+Prettier+Vetur常用配置
工程里创建文件.eslintrc.js module.exports = {root: true,parserOptions: {parser: 'babel-eslint',sourceType: ...
- 一套流程教你完成基于vue脚手架的vscode代码规范(vetur+eslint+prettier)配置
在写代码的过程当中一般都会要求生产统一风格的代码.规范,简洁的代码好处就不用我多说了吧.接下来就按我的方法来初始化代码生产环境吧. 配置步骤 1.在vscode中下载三个插件 vetur,Pretti ...
- vscode中如何修改vetur配置_vscode 配置vue+vetur+eslint+prettier自动格式化功能
该配置用于vue开发,最终效果是保存时自动根据eslint对js.html和css代码进行格式化. vscode Vetur插件 Vetur插件用于识别vue文件,原本vetur自带格式化功能,但是和 ...
- 首选项配置+Eslint+prettier+Vetur
0.需要安装如下扩展 首选项配置里面有使用到,需要以上四个格式化工具配合使用. 需要注意的是,eslint启用后如果出现import有下划线等错误,需要注意右下角有没有禁用: 点击开启即可. Esli ...
- VScode配置prettier和eslint
前端工具中如果使用prettier进行代码格式化,eslint进行错误检测.对前端工作有极大的帮助 原则: prettier和eslint配置可以分成两种,一种是本地配置,一种是全局配置.VScode ...
最新文章
- 谈谈Linux内核驱动的coding style
- Unity学习笔记3 简易2D横版RPG游戏制作(三)
- redhat6.5 yum register 问题
- php中提示注意怎么解决,PHP中操作MySQL时一定要注意
- destoon代码从头到尾捋一遍
- MOCTF-Web-死亡退出
- 使用Azure人脸API对图片进行人脸识别
- NQueens, NQueens2 N皇后问题,递归回溯
- 华为P30现身华为新加坡官网:坐实水滴屏
- 基于JAVA+SpringMVC+MYSQL的实验室预约管理系统
- vue前端动态分页模板(记录)
- 基于visual Studio2013解决面试题之0909移动星号
- 前端开发-jQuery基本语法
- linux随手笔记(Centos为主)
- 2018-08-14 UnmarshalException: 意外的元素 (uri:, local:customer)
- mysql多表关联查询慢_mysql数据库多表关联查询的慢SQL优化
- 【间歇性努力,不是真正的努力】
- [js高手之路]jquery插件开发实战-选项卡详解
- 什么是函数式编程?总结
- 浅析PC机串口通讯流控制
热门文章
- 精准营销、批量提取QQ群成员号码
- ORB-SLAM2 --- LoopClosing::ComputeSim3 函数
- Getaverse,走向Web3的远方桥梁
- iOS配置证书:Provisioning profile xx_Distribution doesn't include signing certificate iPhone Developer
- CC防御过程中,WAF的主要特点有哪些?
- 与NC对接传输凭证等数据, xml格式文件传输
- 家里WiFi信号差的问题你碰到过吗?WiFi Mesh路由或许能够解决
- 【bat批处理脚本命令】2分钟看懂,一键主机windows系统远程连接控制阿里云等windows系统的云服务器(保姆级图文+实现代码)
- 参加中国移动开发者大会有感
- MAC、IP、ARP协议