Attempting to make web apps browser compatible is not an easy task. Think about it: How many browsers are available out there? How many versions does each one have? Does my JS bundle need to support all these browsers? What are the web features that are safe to use that do not require fallbacks?
Web Baseline a concept introduced by Google to help developers understand which web features are safe to use across all modern browsers without requiring polyfills or fallbacks.
Web Baseline refers to the set of web platform features that are consistently supported by all core modern browsers (Chrome, Firefox, Safari, Edge) at a given point in time.
Moving Targets
Fixed Targets
You can check all Web Baseline features by year
Here comes the role of Browserslist ...
Browserslist is a tool that allows developers to specify the range of browsers their project should support. This configuration informs various tools like Babel, Autoprefixer, PostCSS, ESLint, Stylelint, and webpack, enabling them to adjust their behavior (such as adding polyfills or prefixes) based on the specified browser targets.
To simplify targeting widely supported web features, you can use the browserslist-config-baseline
package. This package provides predefined configurations that align with the Web Baseline, allowing you to specify browser support based on Baseline levels.
in your package.json
add the following:
Tools like Stylelint can leverage the Baseline configuration to warn about CSS features not supported in the targeted browsers. By integrating browserslist-config-baseline
, you can ensure that your stylesheets adhere to the desired level of browser compatibility.
Integrating Baseline with Babel (via @babel/preset-env
) can lead to more efficient builds. By targeting only the necessary transformations for the specified Baseline, you can reduce the output size of your JavaScript files. For instance, targeting Baseline 2020 may result in significantly smaller bundle sizes compared to default settings, as fewer polyfills and syntax transformations are needed.
browserslist-config-baseline
with Babel:Source: Use Baseline with Browserslist