webpack eslint entry-level tutorials

eslint also known as code quality detection that white is to help you detect problems in your code

1. still the same old way and just start a walking program

First you first with a good foundation of webpack projects have talked about this before I would not repeat explained  

Installation depends npm i -D eslint eslint-loader

Configuring eslint in package.json startup command file (which is added to scripts)

"eslint_init": "eslint --init"

3. Start npm run eslint_init the command line

Then choose according to the specific circumstances of the first detection is only the second syntax is more than just syntax also detect other problems with the third is not a normal person, he will not test your code is the standard criteria such as spaces there is no knock, etc. etc. will make people mad pull

4. After you have finished selecting the next time you generate a catalog file .eslintrc.js

Here are some basic configuration you can also manually add some configuration specific reference may want to increase what eslint official website anyway, feeling after I read some of the hair out

module.exports = {
    "env": {
        "browser": true,    //环境是浏览器
        "es6": true
    },
    "extends": "eslint:recommended",
    "globals": {
        "Atomics": "readonly",
        "SharedArrayBuffer": "readonly"
    },
    "parserOptions": {
        "ecmaVersion": 2018,    // ecma版本 2018
        "sourceType": "module"
    },
    "rules": {
        "indent":["error",2],      //  检测代码缩进
        "quotes":["error","double"] // string must be double quotes is being given single quotes }; 
    }

5. Change the file webpack.config.js

Module1: {
        the rules: [
            {
                Test:. / \ (JS | JSX) $ / I,
                Loader: 'eslint-Loader',
                the exclude: / the node_modules | bower_modules /, ignoring the file //
                Options: {}
            }
        ]
    },

This time your code will not be detected recommendations 6. Start webpack project files need to be so strict crazy person would, of course, companies require specific situation

Published 116 original articles · won praise 64 · views 7470

Guess you like

Origin blog.csdn.net/yunchong_zhao/article/details/104117840