Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/litson/polyfilla
一个轻量级的polyfill加载器
https://github.com/litson/polyfilla
loader polyfills shim
Last synced: 15 days ago
JSON representation
一个轻量级的polyfill加载器
- Host: GitHub
- URL: https://github.com/litson/polyfilla
- Owner: litson
- License: mit
- Created: 2017-10-09T05:42:03.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-05-07T07:24:29.000Z (over 6 years ago)
- Last Synced: 2024-11-09T05:37:47.796Z (2 months ago)
- Topics: loader, polyfills, shim
- Language: JavaScript
- Homepage:
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PolyfillA
一个轻量级的`polyfill`加载器。
用户可以配置需要的 `polyfill` ,当浏览器需要 TA 的时候,则会去加载该(或多个) `polyfill` ,当加载完毕,则会运行回调。
## API
### Polyfilla.config( name, [config])
- `{String | Object} name` 新增/修改 “一个” 或者“许多” `polyfill`
- `{Object} [config]` 配置
- `{String} url` `polyfill` 的获取地址
- `{function} condition` 触发下载 `polyfill` 的条件
- 用法
```js// 批量配置
Polyfilla.config(
{
promise: {
url: 'https://cdn.bootcss.com/es6-promise/4.1.1/es6-promise.min.js',
// 若当期浏览器支持Promise,则不会下载polyfill
condition() {
return window.Promise
}
},
fetch : {
url: 'https://cdn.bootcss.com/fetch/2.0.3/fetch.min.js',
condition() {
return window.fetch
}
}
}
)
// 或单独配置
Polyfilla.config(
'fetch',
{
url: 'https://cdn.bootcss.com/fetch/2.0.3/fetch.min.js',
condition() {
return window.fetch
}
}
)```
### Polyfilla( polyfills, [cb] )
- `{Array} polyfills` 所有需要的 `polyfill`
- `{Function} [cb]` 所有需要的 `polyfill` 加载完毕后运行的回调- 用法:
```js
Polyfilla(
[
'fetch',
'promise'
],
() => console.log( window.fetch, window.Promise )
)```