@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.
Files changed (2) hide show
  1. package/README.md +50 -12
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,20 +1,58 @@
1
1
  # esmpack
2
- ESM Pack Packer and Web Server with PostCSS and ESM Loader
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
- # Why?
5
- Because, there is no simple packer that just generates module paths. After ES6 and HTTP2, there is no need to bundle all JavaScripts into a single file. Parsing and loading entire bundle is a single threaded operation, which blocks UI rendering and also consumes very high memory.
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
- # So what does this do?
8
- 1. Creates a single pack JS file which only has import definition of all the imports.
9
- 2. Import map contains inline JavaScript module via data url to inject CSS link into document.
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
- ## Dev Packer
32
+ Will transform to
13
33
 
14
- 1. Development time packer will generate HTML file along with the import map and inline script to host the module.
15
- 2. Dev Packer will generate `let cs = document.currentScript;import("imported-path").then((r) => ESMPack.render(r, cs))` script inside html for every JS's corresponding html.
16
- 3. Library author must implement `ESMPack.render` method which will accept exports from imported method and `currentScript`.
34
+ ```
35
+ ESMPack.installStyleSheet(import.meta.resolve("app.css"));
36
+ ```
17
37
 
18
- ## Release Packer
38
+ # JSON
39
+ ```
40
+ import list from "./countries.json";
41
+ ```
19
42
 
20
- 1. `pack.js` will generate a single JS file that will inject import map into document and it will call `ESMPack.render` method with import.
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@package-verse/esmpack",
3
- "version": "1.0.27",
3
+ "version": "1.0.28",
4
4
  "description": "ESM Pack Packer and Web Server with PostCSS and ESM Loader",
5
5
  "homepage": "https://github.com/package-verse/esmpack#readme",
6
6
  "bugs": {