Created
January 22, 2020 21:55
-
-
Save kentcdodds/48c069462a9ab4223eb93b5e19acee31 to your computer and use it in GitHub Desktop.
Code for my blog post: https://kentcdodds.com/blog/super-simple-start-to-es-modules-in-the-browser
This file contains 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
function appendDiv(message) { | |
const div = document.createElement('div') | |
div.textContent = message | |
document.body.appendChild(div) | |
} | |
export {appendDiv} |
This file contains 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
import {appendDiv} from './append-div.js' | |
function go() { | |
appendDiv('Hello from async script') | |
} | |
export {go} |
This file contains 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
<script type="module"> | |
import {appendDiv} from './append-div.js' | |
appendDiv('Hello from inline script') | |
</script> | |
<script type="module" src="./script-src.js"></script> |
This file contains 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
import {appendDiv} from './append-div.js' | |
appendDiv('Hello from external script') | |
import('./async-script.js').then( | |
moduleExports => { | |
moduleExports.go() | |
}, | |
error => { | |
console.error('there was an error loading the script') | |
throw error | |
}, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment