browserslist

1,491 阅读1分钟

browserslist

1、 package.json

{
  "browserslist": [">1%", "last 2 versions", "not ie <=8"]
}

2、.browserslitrc

# Browsers that we support
[production staging]
Chrome >=70 and not dead and >0.1%
Firefox >=60 and not dead and >0.1%

[development]
Chrome >=80 and not dead and >0.1%

说明

, or or: 表示‘或’,and: 表示‘且’。

使用

  • 1、查看列表方法一
npx browserslist # 打印项目里面配置的浏览器最终结果
npx browserslist "last 1 version, >1%" # 打印您输入的配置的浏览器最终结果

1 2

但是有时网络不好,会出现如下结果: 3

  • 2、查看列表方法二 鉴于上面出现的BUG,我全局安装browserslist,然后可以在控制台手动得到相应结果,而且不会出现bug.
cnpm i -g browserslist
browserslist "> 1%, IE 10"
browserlist "Chrome >=70 and not dead and >0.1%"

屡试不爽!!

4

5

配置

因为我司项目是内部使用,且规定只需要满足chrome 70+firefox 60+,所以才有了上述极简配置!打包后的代码都小了很多,也不用转es5,爽歪歪~~

# Browsers that we support
[production staging]
Chrome >=70 and not dead and >0.1%
Firefox >=60 and not dead and >0.1%

[development]
Chrome >=80 and not dead and >0.1%