Created
June 30, 2023 06:34
-
-
Save mikaelvesavuori/d41a62b1a9856128148878122e1c3b59 to your computer and use it in GitHub Desktop.
Demo of browser-native JavaScript import maps, as adapted from https://web.dev/import-maps-in-all-modern-browsers/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE HTML> | |
| <head> | |
| <title> | |
| Browser import maps demo | |
| </title> | |
| <style> | |
| h1 { | |
| font-family: sans-serif; | |
| } | |
| </style> | |
| <script type="importmap"> | |
| { | |
| "imports": { | |
| "browser-fs-access": "https://unpkg.com/[email protected]/dist/index.modern.js" | |
| } | |
| } | |
| </script> | |
| </head> | |
| <body> | |
| <h1 id="supports"></h1> | |
| <script> | |
| document.querySelector('#supports').innerHTML = (HTMLScriptElement.supports('importmap')) ? 'Your browser supports import maps!' : 'Your browser does not support import maps...'; | |
| </script> | |
| <button>Select a text file</button> | |
| <script type="module"> | |
| import {fileOpen} from 'browser-fs-access'; | |
| const button = document.querySelector('button'); | |
| button.addEventListener('click', async () => { | |
| const file = await fileOpen({ | |
| mimeTypes: ['text/plain'], | |
| }); | |
| console.log(await file.text()); | |
| }); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment