es-module-shims 2.0.3 → 2.0.5
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 +39 -7
- package/dist/es-module-shims-typescript.js +546 -0
- package/dist/es-module-shims.debug.js +370 -351
- package/dist/es-module-shims.js +361 -339
- package/dist/es-module-shims.wasm.js +360 -338
- package/package.json +8 -4
package/README.md
CHANGED
|
@@ -9,8 +9,9 @@ For the remaining ~4% of users, the highly performant (see [benchmarks](#benchma
|
|
|
9
9
|
The following modules features are polyfilled:
|
|
10
10
|
|
|
11
11
|
* [Import Maps](#import-maps) polyfill.
|
|
12
|
-
* [JSON](#json-modules) and [CSS modules](#css-modules) with import assertions
|
|
13
|
-
* [Wasm modules](#wasm-modules) with support for Source Phase Imports
|
|
12
|
+
* [JSON](#json-modules) and [CSS modules](#css-modules) with import assertions when enabled.
|
|
13
|
+
* [Wasm modules](#wasm-modules) with support for Source Phase Imports when enabled.
|
|
14
|
+
* [TypeScript](#typescript) type stripping when enabled.
|
|
14
15
|
|
|
15
16
|
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.
|
|
16
17
|
|
|
@@ -27,7 +28,7 @@ Because we are still using the native module loader the edge cases work out comp
|
|
|
27
28
|
Include ES Module Shims with a `async` attribute on the script, then include an import map and module scripts normally:
|
|
28
29
|
|
|
29
30
|
```html
|
|
30
|
-
<script async src="https://ga.jspm.io/npm:es-module-shims@2.0.
|
|
31
|
+
<script async src="https://ga.jspm.io/npm:es-module-shims@2.0.5/dist/es-module-shims.js"></script>
|
|
31
32
|
|
|
32
33
|
<!-- https://generator.jspm.io/#U2NhYGBkDM0rySzJSU1hKEpNTC5xMLTQM9Az0C1K1jMAAKFS5w0gAA -->
|
|
33
34
|
<script type="importmap">
|
|
@@ -190,7 +191,19 @@ If using more modern features like CSS Modules or JSON Modules, these need to be
|
|
|
190
191
|
|
|
191
192
|
```html
|
|
192
193
|
<script>
|
|
193
|
-
window.esmsInitOptions = { polyfillEnable: ['css-modules', 'json-modules', 'wasm-modules'] }
|
|
194
|
+
window.esmsInitOptions = { polyfillEnable: ['css-modules', 'json-modules', 'wasm-modules', 'typescript'] }
|
|
195
|
+
</script>
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
The above polyfill options correspond to `polyfillEnable: 'all'`.
|
|
199
|
+
|
|
200
|
+
Alternatively options can be set via the `esms-options` script type:
|
|
201
|
+
|
|
202
|
+
```html
|
|
203
|
+
<script type="esms-options">
|
|
204
|
+
{
|
|
205
|
+
"polyfillEnable": "all"
|
|
206
|
+
}
|
|
194
207
|
</script>
|
|
195
208
|
```
|
|
196
209
|
|
|
@@ -297,13 +310,13 @@ In polyfill mode, multiple import maps are supported.
|
|
|
297
310
|
Support for dynamically injecting import maps with JavaScript via e.g.:
|
|
298
311
|
|
|
299
312
|
```js
|
|
300
|
-
document.
|
|
313
|
+
document.head.appendChild(Object.assign(document.createElement('script'), {
|
|
301
314
|
type: 'importmap',
|
|
302
315
|
innerHTML: JSON.stringify({ imports: { x: './y.js' } }),
|
|
303
316
|
}));
|
|
304
317
|
```
|
|
305
318
|
|
|
306
|
-
is also provided using mutation observers.
|
|
319
|
+
is also provided using mutation observers. Note, only `document.head` appending of scripts, importmaps and preloads is supported - we do not observe body mutations to `document.body` for performance reasons.
|
|
307
320
|
|
|
308
321
|
The caveat for multiple import map support polyfill support in browsers that only support a single import map is per the usual "polyfill rule" for es-module-shims - only those top-level graphs with static import feailures can be polyfilled.
|
|
309
322
|
|
|
@@ -531,6 +544,26 @@ const instance = await WebAssembly.instantiate(mod, { /* ...imports */ });
|
|
|
531
544
|
|
|
532
545
|
If using CSP, make sure to add `'unsafe-wasm-eval'` to `script-src` which is needed when the shim or polyfill engages, note this policy is much much safer than eval due to the Wasm secure sandbox. See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src#unsafe_webassembly_execution.
|
|
533
546
|
|
|
547
|
+
### TypeScript Type Stripping
|
|
548
|
+
|
|
549
|
+
Node.js recently [added support for automatically executing TypeScript with type stripping](https://nodejs.org/api/typescript.html). We support the exact same approach in ES Module Shims.
|
|
550
|
+
|
|
551
|
+
Once enabled, the separate `es-module-shims-typescript.js` extension must be available as a sibling asset to `es-module-shims.js` and will then be loaded on demand when a `.ts`, `.mts` file is loaded or when a file is served with the `application/typescript` MIME type.
|
|
552
|
+
|
|
553
|
+
Example:
|
|
554
|
+
|
|
555
|
+
```html
|
|
556
|
+
<script async src="https://ga.jspm.io/npm:es-module-shims@2.0.5/dist/es-module-shims.js"></script>
|
|
557
|
+
<script type="esms-options">
|
|
558
|
+
{
|
|
559
|
+
"polyfillEnable": "all"
|
|
560
|
+
}
|
|
561
|
+
</script>
|
|
562
|
+
<script type="module" src="test.ts"></script>
|
|
563
|
+
```
|
|
564
|
+
|
|
565
|
+
Note that runtime TypeScript features such as enums are not supported, and type only imports should be used where possible, per the Node.js guidance for TypeScript.
|
|
566
|
+
|
|
534
567
|
### Module Workers
|
|
535
568
|
|
|
536
569
|
ES Module Shims can be used in module workers in browsers that provide dynamic import in worker environments, which at the moment are Chrome(80+), Edge(80+), Firefox(~113+) and Safari(15+).
|
|
@@ -575,7 +608,6 @@ Provide a `esmsInitOptions` on the global scope before `es-module-shims` is load
|
|
|
575
608
|
* [nonce](#nonce)
|
|
576
609
|
* [onerror](#error-hook)
|
|
577
610
|
* [onpolyfill](#polyfill-hook)
|
|
578
|
-
* [polyfillEnable](#polyfill-enable-option)
|
|
579
611
|
* [resolve](#resolve-hook)
|
|
580
612
|
* [revokeBlobURLs](#revoke-blob-urls)
|
|
581
613
|
* [shimMode](#shim-mode-option)
|