代码规范

  • 集成editorconfig配置

editorconfig有助于为不同的IDE编辑器上处理同一项目的多个开发人员维护一致的编码风格;


# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true

# Matches multiple files with brace expansion notation
# Set default charset
[*.{js,py}]
charset = utf-8

# 4 space indentation
[*.py]
indent_style = space
indent_size = 4

# Tab indentation (no size specified)
[Makefile]
indent_style = tab

# Indentation override for all JS under lib directory
[lib/**.js]
indent_style = space
indent_size = 2

# Matches the exact files either package.json or .travis.yml
[{package.json,.travis.yml}]
indent_style = space
indent_size = 2

vscode 需要安装一个插件 EditorConfig for VS code

image.png
  • 使用prettier工具
image.png

3 创建.prettierignore 忽略文件

/dist/*
.local
.output.js
/node_modules/**


**/*.svg
**/*.sh

/public/*

image.png
  • 使用ESLint检测
    image.png

    image.png
image.png

image.png

image.png
image.png

image.png

image.png

image.png

image.png
image.png
image.png
const path = require('path')
module.exports = {
  // 1、配置方式一:CLI提供的属性
  outputDir: './build',
  // 2、配置方式二:和webpack属性完全一致,最后进行合并
  // configureWebpack: {
  //   resolve: {
  //     alias: {
  //       commponents: "@/commponents",
  //     },
  //   },
  // },

  // 方式二也可以用函数的方式

  // configureWebpack: (config) => {
  //   config.resolve.alias = {
  //     "@": path.resolve(__dirname, "src"),
  //     commponents: "@/commponents",
  //   };
  // },

  // 方式三:链式方式配置
  chainWebpack: (config) => {
    config.resolve.alias
      .set('@', path.resolve(__dirname, 'src'))
      .set('commponents', '@/commponents')
  }
}


你可能感兴趣的:(代码规范)