es-module-shims 1.6.3 → 1.7.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/README.md +26 -23
- package/dist/es-module-shims.debug.js +938 -0
- package/dist/es-module-shims.js +55 -28
- package/dist/es-module-shims.wasm.debug.js +898 -0
- package/dist/es-module-shims.wasm.js +55 -28
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
# ES Module Shims
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Polyfills import maps and other ES Modules features on top of the baseline native ESM support in browsers.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
With import maps now supported by all major browsers, ES Module Shims entirely bypasses processing for the [74% of users](https://caniuse.com/import-maps) with native import maps support.
|
|
6
6
|
|
|
7
|
-
For the remaining
|
|
7
|
+
For the remaining users, the highly performant (see [benchmarks](#benchmarks)) production and [CSP-compatible](#csp-support) shim kicks in to rewrite module specifiers driven by the [Web Assembly ES Module Lexer](https://github.com/guybedford/es-module-lexer).
|
|
8
8
|
|
|
9
9
|
The following modules features are polyfilled:
|
|
10
10
|
|
|
11
|
-
* [Import Maps](#import-maps)
|
|
11
|
+
* [Import Maps](#import-maps) polyfill.
|
|
12
12
|
* Dynamic `import()` shimming when necessary in eg older Firefox versions.
|
|
13
13
|
* `import.meta` and `import.meta.url`.
|
|
14
14
|
* [JSON](#json-modules) and [CSS modules](#css-modules) with import assertions (when enabled).
|
|
15
|
-
* [`<link rel="modulepreload">`
|
|
15
|
+
* [`<link rel="modulepreload">` is shimmed](#modulepreload) in browsers without import maps support.
|
|
16
16
|
|
|
17
17
|
When running in shim mode, module rewriting is applied for all users and custom [resolve](#resolve-hook) and [fetch](#fetch-hook) hooks can be implemented allowing for custom resolution and streaming in-browser transform workflows.
|
|
18
18
|
|
|
@@ -29,7 +29,7 @@ Because we are still using the native module loader the edge cases work out comp
|
|
|
29
29
|
Include ES Module Shims with a `async` attribute on the script, then include an import map and module scripts normally:
|
|
30
30
|
|
|
31
31
|
```html
|
|
32
|
-
<script async src="https://ga.jspm.io/npm:es-module-shims@1.
|
|
32
|
+
<script async src="https://ga.jspm.io/npm:es-module-shims@1.7.1/dist/es-module-shims.js"></script>
|
|
33
33
|
|
|
34
34
|
<!-- https://generator.jspm.io/#U2NhYGBkDM0rySzJSU1hKEpNTC5xMLTQM9Az0C1K1jMAAKFS5w0gAA -->
|
|
35
35
|
<script type="importmap">
|
|
@@ -84,9 +84,9 @@ For example:
|
|
|
84
84
|
|
|
85
85
|
```html
|
|
86
86
|
<script type="module">
|
|
87
|
-
import './supported.js';
|
|
87
|
+
import './supported-relative-import.js';
|
|
88
88
|
console.log('Static Ok');
|
|
89
|
-
import('
|
|
89
|
+
import('unsupported-import-map').then(x => {
|
|
90
90
|
console.log('Dynamic Ok');
|
|
91
91
|
}, err => {
|
|
92
92
|
console.log('Dynamic Fail');
|
|
@@ -110,9 +110,9 @@ If a static failure is not possible and dynamic import must be used, one alterna
|
|
|
110
110
|
|
|
111
111
|
```html
|
|
112
112
|
<script type="module">
|
|
113
|
-
import './supported.js';
|
|
113
|
+
import './supported-relative-import.js';
|
|
114
114
|
console.log('Static Ok');
|
|
115
|
-
importShim('
|
|
115
|
+
importShim('unsupported-import-map').then(x => {
|
|
116
116
|
console.log('Ok');
|
|
117
117
|
}, err => {
|
|
118
118
|
console.log('Fail');
|
|
@@ -176,7 +176,6 @@ If the polyfill is analyzing or applying to a module script that doesn't need to
|
|
|
176
176
|
</script>
|
|
177
177
|
```
|
|
178
178
|
|
|
179
|
-
|
|
180
179
|
### Polyfill Features
|
|
181
180
|
|
|
182
181
|
If using more modern features like CSS Modules or JSON Modules, these need to be manually enabled via the [`polyfillEnable` init option](#polyfill-enable-option) to raise the native baseline from just checking import maps to also checking that browsers support these features:
|
|
@@ -238,7 +237,7 @@ Browser compatibility **without** ES Module Shims:
|
|
|
238
237
|
| [modulepreload](#modulepreload) | 66+ | :x: | :x: |
|
|
239
238
|
| [Dynamic Import](#dynamic-import) | 63+ | 67+ | 11.1+ |
|
|
240
239
|
| [import.meta.url](#importmetaurl) | ~76+ | ~67+ | ~12+ ❕<sup>1</sup> |
|
|
241
|
-
| [Import Maps](#import-maps) | 89+ |
|
|
240
|
+
| [Import Maps](#import-maps) | 89+ | 108+ | 16.4+ |
|
|
242
241
|
| [JSON Modules](#json-modules) | 91+ | :x: | :x: |
|
|
243
242
|
| [CSS Modules](#css-modules) | 95+ | :x: | :x: |
|
|
244
243
|
| [import.meta.resolve](#resolve) | :x: | :x: | :x: |
|
|
@@ -249,9 +248,9 @@ Browser compatibility **without** ES Module Shims:
|
|
|
249
248
|
|
|
250
249
|
### Import Maps
|
|
251
250
|
|
|
252
|
-
> Stability: WhatWG Standard,
|
|
251
|
+
> Stability: WhatWG Standard, implemented in all browsers although only recently in Firefox and Safari
|
|
253
252
|
|
|
254
|
-
Import maps allow for importing "bare specifiers" in JavaScript modules, which prior to import maps throw in all browsers with native modules support.
|
|
253
|
+
Import maps allow for importing _"bare specifiers"_ in JavaScript modules, which prior to import maps throw in all browsers with native modules support.
|
|
255
254
|
|
|
256
255
|
Using this polyfill we can write:
|
|
257
256
|
|
|
@@ -359,8 +358,10 @@ This tag also supports the `"integrity"`, `"crossorigin"` and `"referrerpolicy"`
|
|
|
359
358
|
|
|
360
359
|
This tag just initiates a fetch request in the browser and thus works equally as a preload polyfill in both shimmed and unshimmed modes, with integrity validation support.
|
|
361
360
|
|
|
361
|
+
In browsers that don't support modulepreload, polyfilled preloading behaviour is provided using an early `fetch()` call with the same request options as the module script, resulting in network-level cache sharing.
|
|
362
|
+
|
|
362
363
|
Unlike the browser specification, the modulepreload polyfill does not request dependency modules by default, in order to avoid unnecessary
|
|
363
|
-
code analysis in the polyfill scenarios
|
|
364
|
+
code analysis in the polyfill scenarios, _it is always recommended to preload deep imports so that this feature shouldn't be necessary._
|
|
364
365
|
|
|
365
366
|
#### Preload shim
|
|
366
367
|
|
|
@@ -368,7 +369,7 @@ When in shim mode, `<link rel="modulepreload-shim" href="/module.js" />` must be
|
|
|
368
369
|
|
|
369
370
|
### CSP Support
|
|
370
371
|
|
|
371
|
-
By default ES Module Shims provides full support for CSP by using the asm.js ES Module Lexer build. This is absolutely identical in performance to the Wasm version in Firefox and Chrome
|
|
372
|
+
By default ES Module Shims provides full support for CSP by using the asm.js ES Module Lexer build. This is absolutely identical in performance to the Wasm version in Firefox and Chrome (in Safari the asm.js version is actually faster than Wasm).
|
|
372
373
|
|
|
373
374
|
The CSP nonce to use for module scripts will be picked up from the first script on the page or via the [`nonce` init option](#nonce).
|
|
374
375
|
|
|
@@ -491,18 +492,19 @@ const worker = new Worker(getWorkerScriptURL('myEsModule.js'));
|
|
|
491
492
|
|
|
492
493
|
Provide a `esmsInitOptions` on the global scope before `es-module-shims` is loaded to configure various aspects of the module loading process:
|
|
493
494
|
|
|
494
|
-
* [shimMode](#shim-mode-option)
|
|
495
|
-
* [polyfillEnable](#polyfill-enable-option)
|
|
496
495
|
* [enforceIntegrity](#enforce-integrity)
|
|
497
|
-
* [
|
|
496
|
+
* [fetch](#fetch-hook)
|
|
497
|
+
* [mapOverrides](#overriding-import-map-entries)
|
|
498
|
+
* [modulepreload](#modulepreload)
|
|
498
499
|
* [noLoadEventRetriggers](#no-load-event-retriggers)
|
|
499
|
-
* [
|
|
500
|
+
* [nonce](#nonce)
|
|
500
501
|
* [onerror](#error-hook)
|
|
501
502
|
* [onpolyfill](#polyfill-hook)
|
|
503
|
+
* [polyfillEnable](#polyfill-enable-option)
|
|
502
504
|
* [resolve](#resolve-hook)
|
|
503
|
-
* [fetch](#fetch-hook)
|
|
504
505
|
* [revokeBlobURLs](#revoke-blob-urls)
|
|
505
|
-
* [
|
|
506
|
+
* [shimMode](#shim-mode-option)
|
|
507
|
+
* [skip](#skip)
|
|
506
508
|
|
|
507
509
|
```html
|
|
508
510
|
<script>
|
|
@@ -519,7 +521,8 @@ window.esmsInitOptions = {
|
|
|
519
521
|
skip: /^https:\/\/cdn\.com/, // defaults to null
|
|
520
522
|
// Clean up blob URLs after execution
|
|
521
523
|
revokeBlobURLs: true, // default false
|
|
522
|
-
// Secure mode to not support loading modules without integrity
|
|
524
|
+
// Secure mode to not support loading modules without integrity
|
|
525
|
+
// (integrity is always verified even when disabled though)
|
|
523
526
|
enforceIntegrity: true, // default false
|
|
524
527
|
// Permit overrides to import maps
|
|
525
528
|
mapOverrides: true, // default false
|