Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/546669204/sw-cjs2esm
让 script module 为所欲为
https://github.com/546669204/sw-cjs2esm
Last synced: 12 days ago
JSON representation
让 script module 为所欲为
- Host: GitHub
- URL: https://github.com/546669204/sw-cjs2esm
- Owner: 546669204
- License: apache-2.0
- Created: 2021-03-23T06:01:00.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-03-23T06:22:24.000Z (almost 4 years ago)
- Last Synced: 2024-11-07T11:23:48.779Z (2 months ago)
- Language: JavaScript
- Size: 7.81 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sw-cjs2esm
让 script module 为所欲为 直接在浏览器中使用 import 引入 cjs库# 使用
在使用esm 之前执行一下代码
```
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('sw.js').then(function(reg) {
// registration worked
console.log('Registration succeeded. Scope is ' + reg.scope);
}).catch(function(error) {
// registration failed
console.log('Registration failed with ' + error);
});
}
```引入示例
```
import XXX from "xxx.com/ccc" // 如果这个库是cjs库import XXX from "xxx.com/ccc?++esm" // 增加?++esm 支持 esm
```
直接在浏览器中使用 import 享受吧。