es-module-shims 2.6.2 → 2.8.0
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 +28 -3
- package/dist/es-module-shims.debug.js +281 -258
- package/dist/es-module-shims.js +272 -249
- package/dist/es-module-shims.wasm.js +272 -249
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ Because we are still using the native module loader the edge cases work out comp
|
|
|
31
31
|
Include ES Module Shims with a `async` attribute on the script, then include an import map and module scripts normally:
|
|
32
32
|
|
|
33
33
|
```html
|
|
34
|
-
<script async src="https://ga.jspm.io/npm:es-module-shims@2.
|
|
34
|
+
<script async src="https://ga.jspm.io/npm:es-module-shims@2.8.0/dist/es-module-shims.js"></script>
|
|
35
35
|
|
|
36
36
|
<!-- https://generator.jspm.io/#U2NhYGBkDM0rySzJSU1hKEpNTC5xMLTQM9Az0C1K1jMAAKFS5w0gAA -->
|
|
37
37
|
<script type="importmap">
|
|
@@ -397,6 +397,20 @@ const importMap = { imports: {/*...*/}, scopes: {/*...*/} };
|
|
|
397
397
|
importShim.addImportMap(importMap);
|
|
398
398
|
```
|
|
399
399
|
|
|
400
|
+
### Module Scripts
|
|
401
|
+
|
|
402
|
+
All module scripts except those with a `noshim` attribute are polyfilled. We support all of the the `defer`, `integrity`, `referrerPolicy`, `fetchPriority` and `crossOrigin` script attribute behaviours when polyfilling.
|
|
403
|
+
|
|
404
|
+
In addition to static module scripts, we also use mutation observers to automatically detect and apply dynamic polyfilling for scripts injected into the head of the page:
|
|
405
|
+
|
|
406
|
+
```js
|
|
407
|
+
document.head.appendChild(Object.assign(document.createElement('script'), {
|
|
408
|
+
innerHTML: `import 'maybe-polyfill-dep'; console.log('loaded');`,
|
|
409
|
+
}));
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
The same attributes as static scripts are also supported.
|
|
413
|
+
|
|
400
414
|
### Shim Import
|
|
401
415
|
|
|
402
416
|
Dynamic `import(...)` within any modules loaded will be rewritten as `importShim(...)` automatically providing full support for all es-module-shims features through dynamic import.
|
|
@@ -455,6 +469,17 @@ import pkg from 'pkg';
|
|
|
455
469
|
</script>
|
|
456
470
|
```
|
|
457
471
|
|
|
472
|
+
## Trusted Types Support
|
|
473
|
+
|
|
474
|
+
ES Module Shims supports [Trusted Types](https://developer.mozilla.org/en-US/docs/Web/API/Trusted_Types_API) a browser security feature that prevents DOM-based XSS attacks. When your CSP includes `require-trusted-types-for 'script'`, the library automatically creates a policy named `es-module-shims` to handle its internal script creation and source rewriting. Browsers without Trusted Types support fall back to standard behavior automatically.
|
|
475
|
+
|
|
476
|
+
To enable it, add `es-module-shims` to your CSP's trusted-types directive. If you see errors about "TrustedScript assignment," you're missing this directive.
|
|
477
|
+
|
|
478
|
+
```html
|
|
479
|
+
<meta http-equiv="Content-Security-Policy"
|
|
480
|
+
content="require-trusted-types-for 'script'; trusted-types es-module-shims;">
|
|
481
|
+
```
|
|
482
|
+
|
|
458
483
|
#### Wasm Build
|
|
459
484
|
|
|
460
485
|
To use the Web Assembly / non-CSP build of ES Module Shims, this is available as a self-contained single file at `es-module-shims/wasm` or `es-module-shims/dist/es-module-shims.wasm.js` in the package folder.
|
|
@@ -781,7 +806,7 @@ For example, if lazy loading `<script type="module-shim">` scripts alongside sta
|
|
|
781
806
|
|
|
782
807
|
DOM `load` events are fired for all `"module-shim"` scripts both for success and failure just like for native module scripts.
|
|
783
808
|
|
|
784
|
-
###
|
|
809
|
+
### Polyfill Enable Option
|
|
785
810
|
|
|
786
811
|
The `polyfillEnable` option allows enabling polyfill features which are newer and would otherwise result in unnecessary polyfilling in modern browsers that haven't yet updated.
|
|
787
812
|
|
|
@@ -799,7 +824,7 @@ In adddition, the `"all"` option will enable all features.
|
|
|
799
824
|
|
|
800
825
|
The reason the `polyfillEnable` option is needed is because ES Module Shims implements a performance optimization where if a browser supports modern modules features to an expected baseline of import maps support, it will skip all polyfill source analysis resulting in full native passthrough performance.
|
|
801
826
|
|
|
802
|
-
###
|
|
827
|
+
### Polyfill Disable Option
|
|
803
828
|
|
|
804
829
|
Conversely to `polyfillEnable` it can be beneficial to dissable unused features where excluding those features from the baseline allows avoiding unnecessary feature detections or unnecessary analysis of module graphs.
|
|
805
830
|
|