Scan Javascript for browser compatibility

前端 未结 4 1500
情书的邮戳
情书的邮戳 2021-02-04 03:41

Is there a tool out there to scan my Javascript code for functions that may not be present in all browsers?

My library is completely non-UI, so I don\'t care about how

4条回答
  •  一向
    一向 (楼主)
    2021-02-04 04:35

    You can use eslint-plugin-compat, a plugin for the ESlint linting utility. You can even use Browserlist to configure the browsers you want to support.

    Installation is very easy. You'll have to install eslint and this plugin:

    npm install --save-dev eslint-plugin-compat
    

    or

    yarn add --dev eslint eslint-plugin-compat
    

    And add a ESlint configuration file:

    // .eslintrc
    {
      "extends": ["plugin:compat/recommended"]
    }
    

    Add the supported browsers to your package.json file:

    // sample configuration (package.json)
    {
      // ...
      "browserslist": ["last 2 Chrome versions", "IE 11"],
    }
    

    And then run the linter:

    eslint yourfile.js
    

    In my case this was the output:

    92:9   error  Promise.all() is not supported in IE 11  compat/compat
    94:9   error  Promise.all() is not supported in IE 11  compat/compat
    

提交回复
热议问题