es-module-shims 0.13.0 → 0.15.1
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/CHANGELOG.md +208 -0
- package/README.md +102 -42
- package/dist/es-module-shims.csp.js +768 -0
- package/dist/es-module-shims.js +235 -184
- package/index.d.ts +52 -33
- package/package.json +12 -7
- package/dist/es-module-shims.min.js +0 -2
- package/dist/es-module-shims.min.js.map +0 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
ES Module Shims 0.15.1 (2021/09/18)
|
|
2
|
+
* Significant performance improvements to CSP build via asm.js (https://github.com/guybedford/es-module-shims/pull/190) and direct dynamic import (https://github.com/guybedford/es-module-shims/pull/191)
|
|
3
|
+
|
|
4
|
+
ES Module Shims 0.15.0 (2021/09/17)
|
|
5
|
+
* Various perf and behaviour polishing (https://github.com/guybedford/es-module-shims/pull/188)
|
|
6
|
+
* Revert DOM mutator nested queryString checks (https://github.com/guybedford/es-module-shims/pull/189)
|
|
7
|
+
* Fetch pooling (https://github.com/guybedford/es-module-shims/pull/184)
|
|
8
|
+
|
|
9
|
+
ES Module Shims 0.14.0 (2021/09/13)
|
|
10
|
+
* CSP compatible ES Module Shims build (https://github.com/guybedford/es-module-shims/pull/183)
|
|
11
|
+
|
|
12
|
+
ES Module Shims 0.13.1 (2021/09/10)
|
|
13
|
+
* Fix to ensure global script errors always propagate to the console (https://github.com/guybedford/es-module-shims/pull/182)
|
|
14
|
+
|
|
15
|
+
ES Module Shims 0.13.0 (2021/09/07)
|
|
16
|
+
* Breaking Change: Polyfill mode restricts behaviours to native baseline support (https://github.com/guybedford/es-module-shims/pull/173)
|
|
17
|
+
* Breaking Change: JSON and CSS modules require explicit enabling (https://github.com/guybedford/es-module-shims/pull/172)
|
|
18
|
+
* Breaking Change: Adds the "exports" field to encapsulate the package entry point (https://github.com/guybedford/es-module-shims/pull/177)
|
|
19
|
+
* Feature: Support script DOM "load" events (https://github.com/guybedford/es-module-shims/pull/170)
|
|
20
|
+
* Improve browser compatibility for Weixin browser (https://github.com/guybedford/es-module-shims/pull/165, @xxgjzftd)
|
|
21
|
+
* Fix dynamic import polyfill recursion in Firefox 60 (https://github.com/guybedford/es-module-shims/pull/176)
|
|
22
|
+
* Change compat to Edge 17+ (https://github.com/guybedford/es-module-shims/pull/178)
|
|
23
|
+
|
|
24
|
+
ES Module Shims 0.12.8 (2021/08/24)
|
|
25
|
+
* Fix preload deduping for re-injection of preloads (https://github.com/guybedford/es-module-shims/pull/164)
|
|
26
|
+
|
|
27
|
+
ES Module Shims 0.12.7 (2021/08/23)
|
|
28
|
+
* Support re-triggering DOM load events for static script executions (https://github.com/guybedford/es-module-shims/pull/162)
|
|
29
|
+
|
|
30
|
+
ES Module Shims 0.12.6 (2021/08/20)
|
|
31
|
+
* Fix regression where inline scripts in polyfill mode on supported browsers would throw an unnecessary error (https://github.com/guybedford/es-module-shims/pull/159)
|
|
32
|
+
|
|
33
|
+
ES Module Shims 0.12.5 (2021/08/19)
|
|
34
|
+
* Support CSS module scripts (https://github.com/guybedford/es-module-shims/pull/154)
|
|
35
|
+
|
|
36
|
+
ES Module Shims 0.12.4 (2021/08/18)
|
|
37
|
+
* Fix eager modulepreload preloading bug from 0.12.3 (https://github.com/guybedford/es-module-shims/pull/152)
|
|
38
|
+
|
|
39
|
+
ES Module Shims 0.12.3 (2021/08/17)
|
|
40
|
+
* Support resolve hook (https://github.com/guybedford/es-module-shims/pull/146, @zhoukekestar)
|
|
41
|
+
* Internal preload cache to avoid double network requests (https://github.com/guybedford/es-module-shims/pull/149)
|
|
42
|
+
|
|
43
|
+
ES Module Shims 0.12.2 (2021/07/23)
|
|
44
|
+
* Support processing nested tags in mutaton observer (https://github.com/guybedford/es-module-shims/pull/144, @dbackeus)
|
|
45
|
+
|
|
46
|
+
ES Module SHims 0.12.1 (2021/06/29)
|
|
47
|
+
* Fixup dynamic injection of modulepreload (f231485)
|
|
48
|
+
|
|
49
|
+
ES Module Shims 0.12.0 (2021/06/29)
|
|
50
|
+
* Support modulepreload polyfilling (https://github.com/guybedford/es-module-shims/pull/141)
|
|
51
|
+
|
|
52
|
+
ES Module Shims 0.11.1 (2021/06/17)
|
|
53
|
+
* Fixup replacement offset regression (https://github.com/guybedford/es-module-shims/pull/140)
|
|
54
|
+
|
|
55
|
+
ES Module Shims 0.11.0 (2021/06/15)
|
|
56
|
+
* Support for JSON modules and import assertions (https://github.com/guybedford/es-module-shims/commit/2d7eb193986d51733fa6394ad699ee70e5060a13)
|
|
57
|
+
* Fix dynamic import bug in Firefox <67 (https://github.com/guybedford/es-module-shims/commit/3f3d71fc3dd76ba1a965ae00285823672f34c138)
|
|
58
|
+
|
|
59
|
+
ES Module Shims 0.10.7 (2021/06/10)
|
|
60
|
+
* Fix import map feature detection in Safari (https://github.com/guybedford/es-module-shims/pull/131, @heypiotr)
|
|
61
|
+
|
|
62
|
+
ES Module Shims 0.10.6 (2021/06/05)
|
|
63
|
+
* Support for revoking blob URLs (https://github.com/guybedford/es-module-shims/pull/124, @vovacodes)
|
|
64
|
+
* Include typescript types in published package (https://github.com/guybedford/es-module-shims/pull/125, @vovacodes)
|
|
65
|
+
* Fix support for dynamic import in inline scripts (https://github.com/guybedford/es-module-shims/pull/128)
|
|
66
|
+
* Polyfill bug fixes (https://github.com/guybedford/es-module-shims/pull/130)
|
|
67
|
+
|
|
68
|
+
ES Module Shims 0.10.5 (2021/05/14)
|
|
69
|
+
* Fix immediately added dynamic import maps (https://github.com/guybedford/es-module-shims/pull/123, @vovacodes)
|
|
70
|
+
* Handle relative sourceURL and sourceMappingURL (https://github.com/guybedford/es-module-shims/pull/122, @vovacodes)
|
|
71
|
+
|
|
72
|
+
ES Module Shims 0.10.4 (2021/04/11)
|
|
73
|
+
* Fix cycle handling regression (https://github.com/guybedford/es-module-shims/issues/119)
|
|
74
|
+
|
|
75
|
+
ES Module Shims 0.10.3 (2021/03/22)
|
|
76
|
+
* Fix shim mode execution bug (https://github.com/guybedford/es-module-shims/issues/117)
|
|
77
|
+
|
|
78
|
+
ES Module Shims 0.10.2 (2021/03/18)
|
|
79
|
+
* Fix inline module-shim execution in non-polyfill mode (https://github.com/guybedford/es-module-shims/issues/115)
|
|
80
|
+
* Bug fix for scope key resolution to be relative to baseURL not scopeURL (https://github.com/guybedford/es-module-shims/pull/116)
|
|
81
|
+
|
|
82
|
+
ES Module Shims 0.10.1 (2021/02/27)
|
|
83
|
+
* Various bug fixes for polyfill mode
|
|
84
|
+
|
|
85
|
+
ES Module Shims 0.10.0 (2021/02/27)
|
|
86
|
+
* Feature: Comprehensive polyfill mode (https://github.com/guybedford/es-module-shims/pull/113)
|
|
87
|
+
|
|
88
|
+
ES Module Shims 0.9.0 (2021/01/23)
|
|
89
|
+
* Breaking: New initialOptions global API instead of hooking importShims properties (https://github.com/guybedford/es-module-shims/pull/109, @lewisl9029)
|
|
90
|
+
* Fix inline script double execution issue (https://github.com/guybedford/es-module-shims/pull/111)
|
|
91
|
+
|
|
92
|
+
ES Module Shims 0.8.0 (2020/12/23)
|
|
93
|
+
* Fix URL to URL import map mappings (https://github.com/guybedford/es-module-shims/pull/107, @vovacodes)
|
|
94
|
+
* Include TypeScript types (https://github.com/guybedford/es-module-shims/pull/104, @ifiokjr)
|
|
95
|
+
* Fix processScripts to permit dynamic additions (https://github.com/guybedford/es-module-shims/pull/102, @ifiokjr)
|
|
96
|
+
* Remove unnecessary sourceMappingURL rebase (https://github.com/guybedford/es-module-shims/pull/98)
|
|
97
|
+
|
|
98
|
+
ES Module Shims 0.7.1 (2020/10/30)
|
|
99
|
+
* Update to es-module-shims@0.3.26
|
|
100
|
+
* Fixup onerror hook to throw by default (#96)
|
|
101
|
+
|
|
102
|
+
ES Module Shims 0.7.0 (2020/10/06)
|
|
103
|
+
* Process scripts in order, global importShims.onerror hook (a3e3f639e835d6)
|
|
104
|
+
|
|
105
|
+
ES Module Shims 0.6.0 (2020/09/17)
|
|
106
|
+
* Resolve scopes to the baseURL not the scopeURL (d2893159e4b66c43)
|
|
107
|
+
|
|
108
|
+
ES Module Shims 0.5.2 (2020/08/07)
|
|
109
|
+
* import.meta.resolve (https://github.com/guybedford/es-module-shims/pull/89)
|
|
110
|
+
|
|
111
|
+
ES Module Shims 0.5.0 (2020/07/24)
|
|
112
|
+
* Dynamic import map support (https://github.com/guybedford/es-module-shims/pull/85)
|
|
113
|
+
* Remove support for array fallbacks, builtin modules, workers, CSS modules, JSON modules, Wasm modules (https://github.com/guybedford/es-module-shims/pull/84)
|
|
114
|
+
* Depcache implementation (https://github.com/guybedford/es-module-shims/pull/78)
|
|
115
|
+
|
|
116
|
+
ES Module Shims 0.4.6 (2019/10/21)
|
|
117
|
+
* Implement fetch hook (https://github.com/guybedford/es-module-shims/pull/73)
|
|
118
|
+
|
|
119
|
+
ES Module Shims 0.4.5 (2019/09/18)
|
|
120
|
+
* Fixup incorrect pageBaseUrl reference (7391880e836712)
|
|
121
|
+
* Fixup hasDocument check for Firefox (https://github.com/guybedford/es-module-shims/issues/62)
|
|
122
|
+
|
|
123
|
+
ES Module Shims 0.4.4 (2019/09/09)
|
|
124
|
+
* Fix to ensure build against latest es-module-lexer
|
|
125
|
+
|
|
126
|
+
ES Module Shims 0.4.3 (2019/09/08)
|
|
127
|
+
* Remove unnecessary Object.assign polyfill (https://github.com/guybedford/es-module-shims/commit/6bc90c059377e254e71b6695368215ce6ebff7d7)
|
|
128
|
+
* Rework standard module detection (https://github.com/guybedford/es-module-shims/pull/62)
|
|
129
|
+
|
|
130
|
+
ES Module Shims 0.4.2 (2019/08/31)
|
|
131
|
+
* Fixes a critical Edge bug with parallel execution using a graph inlining to ensure execution order (https://github.com/guybedford/es-module-shims/pull/57, https://github.com/microsoft/ChakraCore/issues/6261)
|
|
132
|
+
* `x-javascript` MIME type support (https://github.com/guybedford/es-module-shims/pull/56)
|
|
133
|
+
|
|
134
|
+
ES Module Shims 0.4.1 (2019/08/30)
|
|
135
|
+
* Support text/javascript MIME type (https://github.com/guybedford/es-module-shims/pull/53)
|
|
136
|
+
|
|
137
|
+
ES Module Shims 0.4.0 (2019/08/29)
|
|
138
|
+
* Support for cascading import maps (https://github.com/guybedford/es-module-shims/pull/49)
|
|
139
|
+
* Use strict Content-Type checks for modules (https://github.com/guybedford/es-module-shims/pull/47)
|
|
140
|
+
|
|
141
|
+
ES Module Shims 0.3.2 (2019/08/29)
|
|
142
|
+
* Update to ES module lexer 0.3.12
|
|
143
|
+
|
|
144
|
+
ES Module Shims 0.3.1 (2019/08/28)
|
|
145
|
+
* Updates to ES module lexer 0.3.11 including better errors and invalid syntax handling (https://github.com/guybedford/es-module-shims/pull/46)
|
|
146
|
+
|
|
147
|
+
ES Module Shims 0.3.0 (2019/08/25)
|
|
148
|
+
* Implement CSS modules (https://github.com/guybedford/es-module-shims/pull/41)
|
|
149
|
+
* Upgrade to Wasm-based ES module lexer for performance (https://github.com/guybedford/es-module-shims/38)
|
|
150
|
+
* Fix sourceMappingURL support in Firefox (https://github.com/guybedford/es-module-shims/pull/37, @MicahZoltu)
|
|
151
|
+
* Separate ES module lexer into its own project (https://github.com/guybedford/es-module-shims/pull/36, @LarsDenBakker)
|
|
152
|
+
|
|
153
|
+
ES Module Shims 0.2.15 (2019/07/28)
|
|
154
|
+
* Early import map resolution (https://github.com/guybedford/es-module-shims/pull/32)
|
|
155
|
+
|
|
156
|
+
ES Module Shims 0.2.14 (2019/07/17)
|
|
157
|
+
* Support import map fallbacks by ignoring std modules (https://github.com/guybedford/es-module-shims/pull/28, @thepassle)
|
|
158
|
+
* Support path separators in module URLs containing hashes and query strings (https://github.com/guybedford/es-module-shims/pull/30, @LarsDenBakker)
|
|
159
|
+
|
|
160
|
+
ES Module Shims 0.2.13 (2019/06/29)
|
|
161
|
+
* Support JSON module imports (https://github.com/guybedford/es-module-shims/pull/27)
|
|
162
|
+
|
|
163
|
+
ES Module Shims 0.2.12 (2019/06/29)
|
|
164
|
+
* Support `<base>` tag for baseURL (https://github.com/guybedford/es-module-shims/pull/26, @LarsDenBakker)
|
|
165
|
+
|
|
166
|
+
ES Module Shims 0.2.11 (2019/06/26)
|
|
167
|
+
* Fix use of object spread in Edge (https://github.com/guybedford/es-module-shims/pull/25, @LarsDenBakker)
|
|
168
|
+
|
|
169
|
+
ES Module Shims 0.2.10 (2019/06/25)
|
|
170
|
+
* Fix Worker constructor options bug (https://github.com/guybedford/es-module-shims/pull/23)
|
|
171
|
+
|
|
172
|
+
ES Module Shims 0.2.9 (2019/06/24)
|
|
173
|
+
* Fixup WorkerShim worker output
|
|
174
|
+
|
|
175
|
+
ES Module Shims 0.2.8 (2019/06/24)
|
|
176
|
+
* Support WorkerShim module workers (https://github.com/guybedford/es-module-shims/pull/17 by @costingeana)
|
|
177
|
+
|
|
178
|
+
ES Module Shims 0.2.7 (2019/05/04)
|
|
179
|
+
* Fix imports minification case (https://github.com/guybedford/es-module-shims/issues/11)
|
|
180
|
+
|
|
181
|
+
ES Module Shims 0.2.6 (2019/04/30)
|
|
182
|
+
* Fixup dynamic import regression
|
|
183
|
+
|
|
184
|
+
ES Module Shims 0.2.5 (2019/04/30)
|
|
185
|
+
* Fix various lexing edge cases around dynamic import
|
|
186
|
+
|
|
187
|
+
ES Module Shims 0.2.4
|
|
188
|
+
* Add "type": "module" to package.json
|
|
189
|
+
|
|
190
|
+
ES Module Shims 0.2.3 (2019/03/29)
|
|
191
|
+
* Fixup minification build
|
|
192
|
+
* Further lexer adjustments (2ca2589b1)
|
|
193
|
+
|
|
194
|
+
ES Module Shims 0.2.2 (2019/03/28)
|
|
195
|
+
* Fixup export syntax parser bug (51396799)
|
|
196
|
+
|
|
197
|
+
ES Module Shims 0.2.1 (2019/02/25)
|
|
198
|
+
* Fix support for URL imports
|
|
199
|
+
|
|
200
|
+
ES Module Shims 0.2.0 (2019/01/12)
|
|
201
|
+
* Update to latest import maps spec (e6e64748)
|
|
202
|
+
|
|
203
|
+
ES Module Shims 0.1.15 (2018/10/09)
|
|
204
|
+
* Use responseURL for resolution for spec compliant redirects (689aed0)
|
|
205
|
+
|
|
206
|
+
ES Module Shims 0.1.14 (2018/10/06)
|
|
207
|
+
* Fix Safari WASM support (7cf31ac4)
|
|
208
|
+
* add sourceURL to cycle shells for debugging (80438731)
|
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
But modules features like Import Maps will take a while to be supported in browsers.
|
|
8
8
|
|
|
9
|
-
_It turns out that we can actually polyfill new modules features on top of these baseline implementations in a performant
|
|
9
|
+
_It turns out that we can actually polyfill new modules features on top of these baseline implementations in a performant 9.5KB shim._
|
|
10
10
|
|
|
11
11
|
This includes support for:
|
|
12
12
|
|
|
@@ -34,10 +34,10 @@ For example, from CDN:
|
|
|
34
34
|
|
|
35
35
|
```html
|
|
36
36
|
<!-- UNPKG -->
|
|
37
|
-
<script async src="https://unpkg.com/es-module-shims@0.
|
|
37
|
+
<script async src="https://unpkg.com/es-module-shims@0.15.1/dist/es-module-shims.js"></script>
|
|
38
38
|
|
|
39
39
|
<!-- JSPM.IO -->
|
|
40
|
-
<script async src="https://ga.jspm.io/npm:es-module-shims@0.
|
|
40
|
+
<script async src="https://ga.jspm.io/npm:es-module-shims@0.15.1/dist/es-module-shims.js"></script>
|
|
41
41
|
```
|
|
42
42
|
|
|
43
43
|
Then there are two ways to use ES Module Shims: Polyfill Mode and [Shim Mode](#shim-mode).
|
|
@@ -177,22 +177,20 @@ In shim mode, external import maps are fully supported.
|
|
|
177
177
|
|
|
178
178
|
#### Dynamic Import Maps
|
|
179
179
|
|
|
180
|
-
Support for dynamically injecting import maps with JavaScript via
|
|
180
|
+
Support for dynamically injecting import maps with JavaScript via eg:
|
|
181
181
|
|
|
182
182
|
```js
|
|
183
183
|
document.body.appendChild(Object.assign(document.createElement('script'), {
|
|
184
184
|
type: 'importmap',
|
|
185
|
-
innerHTML: JSON.stringify({ imports: { x: './y.js' } })
|
|
185
|
+
innerHTML: JSON.stringify({ imports: { x: './y.js' } }),
|
|
186
186
|
}));
|
|
187
187
|
```
|
|
188
188
|
|
|
189
|
-
is supported in Chromium, provided it is injected before any module loads and there is no other import map.
|
|
189
|
+
is supported in Chromium, provided it is injected before any module loads and there is no other import map yet loaded (multiple import maps are not supported).
|
|
190
190
|
|
|
191
|
-
Both modes in ES Module Shims
|
|
191
|
+
Both modes in ES Module Shims support dynamic injection using DOM Mutation Observers.
|
|
192
192
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
In shim mode, full support for dynamic injection of `"importmap-shim"` is provided.
|
|
193
|
+
While in polyfill mode the same restrictions apply that multiple import maps, import maps with a `src` attribute, and import maps loaded after the first module load are not supported, in shim mode all of these behaviours are fully enabled for `"importmap-shim"`.
|
|
196
194
|
|
|
197
195
|
### Dynamic Import
|
|
198
196
|
|
|
@@ -342,7 +340,9 @@ Adding the `"noshim"` attribute to the script tag will also ensure that ES Modul
|
|
|
342
340
|
|
|
343
341
|
Native module scripts only fire `'load'` events but not `'error'` events per the specification.
|
|
344
342
|
|
|
345
|
-
In polyfill mode, DOM `'load'` events are always retriggered, such that the second load event can be reliably considered the polyfill completion, fired for both success and failure completions like the native loader, and always twice (once from the native loader, secondly by the polyfill), whether or not the polyfill actually resulted in execution.
|
|
343
|
+
In polyfill mode, DOM `'load'` events are always retriggered, such that the second load event can be reliably considered the polyfill completion, fired for both success and failure completions like the native loader (except in Safari which uniquely fires the module script error event), and always twice (once from the native loader, secondly by the polyfill), whether or not the polyfill actually resulted in execution.
|
|
344
|
+
|
|
345
|
+
This behaviour can be disabled via the [`noLoadEventRetriggers` option](#no-load-event-retriggers).
|
|
346
346
|
|
|
347
347
|
To dynamically load a module and get a callback once its execution has been triggered or failed, the following code snippet can therefore be used:
|
|
348
348
|
|
|
@@ -350,13 +350,19 @@ To dynamically load a module and get a callback once its execution has been trig
|
|
|
350
350
|
function loadModuleScript (src) {
|
|
351
351
|
return new Promise(resolve => {
|
|
352
352
|
let first = true;
|
|
353
|
+
function callback () {
|
|
354
|
+
if (first) first = false;
|
|
355
|
+
else resolve();
|
|
356
|
+
}
|
|
353
357
|
document.head.appendChild(Object.assign(document.createElement('script'), {
|
|
354
358
|
type: 'module',
|
|
355
359
|
src,
|
|
356
|
-
onload
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
+
onload: callback,
|
|
361
|
+
|
|
362
|
+
// Safari Fix:
|
|
363
|
+
// Safari is the only browser that triggers "error" events instead of "load" events
|
|
364
|
+
// for both error and success like Firefox and Chrome
|
|
365
|
+
onerror: callback
|
|
360
366
|
}));
|
|
361
367
|
});
|
|
362
368
|
}
|
|
@@ -364,15 +370,43 @@ function loadModuleScript (src) {
|
|
|
364
370
|
|
|
365
371
|
Where native module script errors are propagated via `window.onerror`, [`esmsInitOptions.onerror`](#error-hook) can be used to catch polyfill errors.
|
|
366
372
|
|
|
373
|
+
## CSP Build
|
|
374
|
+
|
|
375
|
+
ES Module Shims uses a Web Assembly lexer to execute blob URLs. Web Assembly currently always requires the `unsafe-eval` CSP policy to be set which can weaken the security requirements of an application.
|
|
376
|
+
|
|
377
|
+
For better CSP compatibility an alternative build that uses a JS-based lexer is provided, which offers [comporable performance](https://github.com/guybedford/es-module-lexer#js-build) although with a slower cold start due to leaning more heavily on the JS compiler to kick in for the lexer as opposed to the AOT compilation benefits of using Wasm.
|
|
378
|
+
|
|
379
|
+
This build is exported as `es-module-shims/csp` located at the `dist/es-module-shims.csp.js` file path.
|
|
380
|
+
|
|
381
|
+
CSP compatibility is enabled by adding the `'nonce-...'` CSP nonce rule.
|
|
382
|
+
|
|
383
|
+
The nonce will then be read from the preceding module scripts in the page, or alternatively via the [`nonce` init option](#nonce).
|
|
384
|
+
|
|
385
|
+
A full example of such a CSP workflow is provided below:
|
|
386
|
+
|
|
387
|
+
```html
|
|
388
|
+
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'nonce-n0nce'" />
|
|
389
|
+
<script async src="es-module-shims.csp.js"></script>
|
|
390
|
+
<script type="importmap" nonce="n0nce">
|
|
391
|
+
{
|
|
392
|
+
"pkg": "/pkg.js"
|
|
393
|
+
}
|
|
394
|
+
</script>
|
|
395
|
+
<script type="module" nonce="n0nce">
|
|
396
|
+
import pkg from 'pkg';
|
|
397
|
+
</script>
|
|
398
|
+
```
|
|
399
|
+
|
|
367
400
|
## Init Options
|
|
368
401
|
|
|
369
402
|
Provide a `esmsInitOptions` on the global scope before `es-module-shims` is loaded to configure various aspects of the module loading process:
|
|
370
|
-
|
|
403
|
+
o
|
|
371
404
|
```html
|
|
372
405
|
<script>
|
|
373
406
|
window.esmsInitOptions = {
|
|
374
407
|
shimMode: true, // default false
|
|
375
408
|
polyfillEnable: ['css-modules', 'json-modules'], // default empty
|
|
409
|
+
nonce: 'n0nce', // default null
|
|
376
410
|
noLoadEventRetriggers: true, // default false
|
|
377
411
|
skip: /^https:\/\/cdn\.com/, // defaults to `/^https?:\/\/(cdn\.skypack\.dev|jspm\.dev)\//`
|
|
378
412
|
onerror: (e) => { /*...*/ }, // default noop
|
|
@@ -384,17 +418,31 @@ window.esmsInitOptions = {
|
|
|
384
418
|
<script async src="es-module-shims.js"></script>
|
|
385
419
|
```
|
|
386
420
|
|
|
421
|
+
If only setting JSON-compatible options, the `<script type="esms-options">` can be used instead:
|
|
422
|
+
|
|
423
|
+
```html
|
|
424
|
+
<script type="esms-options">
|
|
425
|
+
{
|
|
426
|
+
"shimMode": true,
|
|
427
|
+
"polyfillEnable": ["css-modules", "json-modules"],
|
|
428
|
+
"nonce": "n0nce"
|
|
429
|
+
}
|
|
430
|
+
</script>
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
This can be convenient when using the [CSP build](#csp-build).
|
|
434
|
+
|
|
387
435
|
See below for a detailed description of each of these options.
|
|
388
436
|
|
|
389
437
|
### Shim Mode Option
|
|
390
438
|
|
|
391
439
|
[Shim Mode](#shim-mode) can be overridden using the `shimMode` option:
|
|
392
440
|
|
|
393
|
-
```
|
|
394
|
-
<script>
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
441
|
+
```html
|
|
442
|
+
<script type="esms-options">
|
|
443
|
+
{
|
|
444
|
+
"shimMode": true
|
|
445
|
+
}
|
|
398
446
|
</script>
|
|
399
447
|
```
|
|
400
448
|
|
|
@@ -408,11 +456,25 @@ The `polyfillEnable` option allows enabling polyfill features which are newer an
|
|
|
408
456
|
|
|
409
457
|
Currently this option supports just `"css-modules"` and `"json-modules"`.
|
|
410
458
|
|
|
459
|
+
```html
|
|
460
|
+
<script type="esms-options">
|
|
461
|
+
{
|
|
462
|
+
"polyfillEnable": ["css-modules", "json-modules"]
|
|
463
|
+
}
|
|
464
|
+
</script>
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
### Nonce
|
|
468
|
+
|
|
469
|
+
The `nonce` option allows setting a CSP nonce to be used with all script injections for full CSP compatibility supported by the [CSP build](#csp-build) of ES Module Shims.
|
|
470
|
+
|
|
471
|
+
Alternatively, add a `blob:` URL policy with the CSP build to get CSP compatibility.
|
|
472
|
+
|
|
411
473
|
```js
|
|
412
|
-
<script>
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
474
|
+
<script type="esms-options">
|
|
475
|
+
{
|
|
476
|
+
"nonce": "n0nce"
|
|
477
|
+
}
|
|
416
478
|
</script>
|
|
417
479
|
```
|
|
418
480
|
|
|
@@ -420,18 +482,16 @@ Currently this option supports just `"css-modules"` and `"json-modules"`.
|
|
|
420
482
|
|
|
421
483
|
Because of the extra processing done by ES Module Shims it is possible for static module scripts to execute after the `DOMContentLoaded` or `readystatechange` events they expect, which can cause missed attachment.
|
|
422
484
|
|
|
423
|
-
In order to ensure libraries that rely on these event still behave correctly, ES Module Shims will double trigger these events
|
|
424
|
-
|
|
425
|
-
These events are carefully only triggered when there definitely were modules that would have missed attachment but there is still the risk that this can result in double attachments when mixing modules and scripts where the scripts might get two events firing.
|
|
485
|
+
In order to ensure libraries that rely on these event still behave correctly, ES Module Shims will always double trigger these events that would normally have executed before the document ready state transition to completion.
|
|
426
486
|
|
|
427
487
|
In such a case, this double event firing can be disabled with the `noLoadEventRetriggers` option:
|
|
428
488
|
|
|
429
489
|
```js
|
|
430
|
-
<script>
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
490
|
+
<script type="esms-options">
|
|
491
|
+
{
|
|
492
|
+
// do not re-trigger DOM events (onreadystatechange, DOMContentLoaded and load events on scripts)
|
|
493
|
+
"noLoadEventRetriggers": true
|
|
494
|
+
}
|
|
435
495
|
</script>
|
|
436
496
|
<script async src="es-module-shims.js"></script>
|
|
437
497
|
```
|
|
@@ -443,10 +503,10 @@ When loading modules that you know will only use baseline modules features, it i
|
|
|
443
503
|
This can be configured by providing a URL regular expression for the `skip` option:
|
|
444
504
|
|
|
445
505
|
```js
|
|
446
|
-
<script>
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
506
|
+
<script type="esms-options">
|
|
507
|
+
{
|
|
508
|
+
skip: "/^https:\/\/cdn\.com/" // defaults to `/^https?:\/\/(cdn\.skypack\.dev|jspm\.dev)\//`
|
|
509
|
+
}
|
|
450
510
|
</script>
|
|
451
511
|
<script async src="es-module-shims.js"></script>
|
|
452
512
|
```
|
|
@@ -518,6 +578,7 @@ Streaming support is also provided, for example here is a hook with streaming su
|
|
|
518
578
|
|
|
519
579
|
```js
|
|
520
580
|
window.esmsInitOptions = {
|
|
581
|
+
shimMode: true,
|
|
521
582
|
fetch: async function (url) {
|
|
522
583
|
const response = await fetch(url);
|
|
523
584
|
if (!response.ok)
|
|
@@ -557,10 +618,10 @@ you might want to reduce the growth of memory usage by revoking those blob URLs
|
|
|
557
618
|
You can do that by enabling the `revokeBlobURLs` init option:
|
|
558
619
|
|
|
559
620
|
```js
|
|
560
|
-
<script>
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
621
|
+
<script type="esms-options">
|
|
622
|
+
{
|
|
623
|
+
"revokeBlobURLs": true
|
|
624
|
+
}
|
|
564
625
|
</script>
|
|
565
626
|
<script type="module" src="es-module-shims.js"></script>
|
|
566
627
|
```
|
|
@@ -573,7 +634,6 @@ cause janks, we recommend enabling this option only if you have done the measure
|
|
|
573
634
|
### Import Rewriting
|
|
574
635
|
|
|
575
636
|
* Sources are fetched, import specifiers are rewritten to reference exact URLs, and then executed as BlobURLs through the whole module graph.
|
|
576
|
-
* CSP is not supported as we're using fetch and modular evaluation.
|
|
577
637
|
* The [lexer](https://github.com/guybedford/es-module-lexer) handles the full language grammar including nested template strings, comments, regexes and division operator ambiguity based on backtracking.
|
|
578
638
|
* When executing a circular reference A -> B -> A, a shell module technique is used to "shim" the circular reference into an acyclic graph. As a result, live bindings for the circular parent A are not supported, and instead the bindings are captured immediately after the execution of A.
|
|
579
639
|
|