Skip to content

Add browserslist depending js validation #7

@alexander-schranz

Description

@alexander-schranz

To avoid the usage of JS functions which are not supported by some browsers we should introduce eslinter for this.

There exist a plugin for this type of linting:

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

Based on the browserslist which can be dumped by running:

npx browserslist

and configured the following way in the project package.json:

    "browserslist": [
        "> 0.25% in my stats",
        "> 0.5% in CH",
        "last 3 version and not dead"
    ]

if a polyfill is added it can be configured the following way:

{
    "root": true,
    "extends": [
        // ...
        "plugin:compat/recommended"
    ],
    "settings": {
        "polyfills": [
            "fetch",
            "Object.values",
            "Object.assign",
            "Promise",
            "URL",
            "URLSearchParams",
            "Symbol",
            "Array.keys",
            "Array.from"
        ]
    },
    // ...
}

polyfills can mostly be included over the exist core-js or whatwg-fetch from github:

import 'whatwg-fetch';
import 'core-js/features/url';
import 'core-js/features/url-search-params';
import 'core-js/features/object/assign';
import 'core-js/features/object/values';
import 'core-js/features/promise';
import 'core-js/features/symbol';
import 'core-js/features/array/keys';
import 'core-js/features/array/from';

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions