@package-verse/esmpack 1.0.27 → 1.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,20 +1,58 @@
|
|
|
1
1
|
# esmpack
|
|
2
|
-
ESM Pack
|
|
2
|
+
1. ESM Pack will only generate import maps for ES modules.
|
|
3
|
+
2. And it will change non JS modules to corresponding `import.meta.resolve`.
|
|
3
4
|
|
|
4
|
-
#
|
|
5
|
-
|
|
5
|
+
# Usage
|
|
6
|
+
Add `ESMPack.render` and `ESMPack.installStyleSheet` before any stylesheet reference
|
|
7
|
+
```
|
|
8
|
+
const ESMPack = ((window as any).ESMPack ||= {});
|
|
9
|
+
ESMPack.installStyleSheet ||= (x: string) => {
|
|
10
|
+
const link = document.createElement("link");
|
|
11
|
+
link.rel = "stylesheet";
|
|
12
|
+
link.href = x;
|
|
13
|
+
if (x.includes(".global.")) {
|
|
14
|
+
document.head.insertAdjacentElement("afterbegin", link);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
document.body.insertAdjacentElement("afterbegin", link);
|
|
18
|
+
}
|
|
6
19
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
20
|
+
ESMPack.render ||= (imports, cs: HTMLScriptElement) => {
|
|
21
|
+
const name = customElements.getName(imports.default);
|
|
22
|
+
const c = document.createElement(name);
|
|
23
|
+
cs.replaceWith(c);
|
|
24
|
+
};
|
|
25
|
+
```
|
|
10
26
|
|
|
27
|
+
# CSS
|
|
28
|
+
```
|
|
29
|
+
import "app.css";
|
|
30
|
+
```
|
|
11
31
|
|
|
12
|
-
|
|
32
|
+
Will transform to
|
|
13
33
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
34
|
+
```
|
|
35
|
+
ESMPack.installStyleSheet(import.meta.resolve("app.css"));
|
|
36
|
+
```
|
|
17
37
|
|
|
18
|
-
|
|
38
|
+
# JSON
|
|
39
|
+
```
|
|
40
|
+
import list from "./countries.json";
|
|
41
|
+
```
|
|
19
42
|
|
|
20
|
-
|
|
43
|
+
Will transform to
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
const list = await (await fetch(import.meta.resolve("./countries.json"))).json();
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
# Media
|
|
50
|
+
```
|
|
51
|
+
import flag from "./flag.jpg";
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Will transform to
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
const flag = import.meta.resolve("./flag.jpg");
|
|
58
|
+
```
|
package/package.json
CHANGED