• 02 vue 项目配置eslint


    直接使用官方推荐的eslint-standard的npm包

    1.安装eslint-standard

    npm i eslint eslint-config-standard eslint-plugin-standard eslint-plugin-promise eslint-plugin-import eslint-plugin-node -D
    

    2.安装npm i eslint-plugin-html 

    此插件可以解析vue里面的js

    npm i eslint-plugin-html
    

    3.在项目的根目录增加 .eslintrc文件

    //.eslintrc
    { "extends": "standard", "plugins": ["html"] }

    4.在package.json里面配置相应的检测文件及目录

    "scripts": {
        "test": "echo "Error: no test specified" && exit 1",
        "lint": "eslint --ext .js --ext .jsx --ext .vue client/", //运行此命令,用于检测
      "lint-fix": "eslint --fix --ext .js --ext .jsx --ext .vue client/", // 运行此命令,进行自动修复代码的格式

    "clean": "rm -rf dist", "build:client": "cross-env NODE_ENV=production webpack --config build/webpack.config.client.js", "build": "npm run clean && npm run build:client", "dev": "cross-env NODE_ENV=development webpack-dev-server --config build/webpack.config.client.js" },

    5.配置写代码时候自动检测  

    npm i eslint-loader babel-eslint -D  

    .eslintrc增加配置:

    {
      "extends": "standard",
      "plugins": [
        "html"
      ],
      "parser": "babel-eslint"
    }
    

    webpack.congif.base.js增加配置

     rules: [
                {
                    test: /.(vue|js|jsx)$/,
                    loader: 'eslint-loader',
                    exclude:/node_modules/,
                    enforce:"pre" //vue-loader处理之前,进行预处理
                }
    ]
    

    6.重新运行项目,改动代码,体验eslint的作用

      

      

     

      

     

  • 相关阅读:
    spring注解方式AOP
    struts2 值栈的理解
    JAVA自定义注解
    JS学习随笔。
    使用Jsoup解析html网页
    Struts迭代器(iterator)遍历List常用的4种例子
    Maven 结合 Spring profile对不同的部署环境打包部署
    打印插件LODOP使用介绍
    Linux下查看CPU信息、机器型号等硬件信息
    验证码的生成和验证
  • 原文地址:https://www.cnblogs.com/ipoodle/p/11028762.html
Copyright © 2020-2023  润新知