Skip to content

Commit a106882

Browse files
committed
fixing up the examples
1 parent 2e0bccf commit a106882

File tree

10 files changed

+24
-7
lines changed

10 files changed

+24
-7
lines changed
1.12 KB
Binary file not shown.

examples/04-browser-modules/app/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ <h1>Browser Modules</h1>
1515
Also, see the MDN docs on <a target="_blank"
1616
href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#browser_compatibility">script tags</a>
1717
</p>
18-
<script type="module" src="index.js"></script>
18+
<script type="module" async src="index.js"></script>
1919
</body>
2020

2121
</html>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function sayHi() {
2+
console.log("Let's bundle this code")
3+
}
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
export function sayHi() {
2-
console.log("Let's bundle this code")
3-
}
1+
import { sayHi } from './sayHi.js'
2+
export { sayHi }

examples/04-browser-modules/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"name": "browser-modules",
3-
"type": "module",
43
"scripts": {
54
"start": "http-server app -p 3000"
65
},
1.12 KB
Binary file not shown.

examples/06-bundle-for-browser/app/index.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
<body>
1010
<h1>Bundle for the Browser</h1>
1111
<p>Check the JavaScript console in the browser</p>
12-
<script src="build.js"></script>
12+
<div>
13+
<button id="button">Load Another Bundle</button>
14+
</div>
15+
<script src="index.js"></script>
1316
</body>
1417

1518
</html>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
import { sayHi } from './utils.js'
22

33
sayHi()
4+
5+
document.getElementById('button').addEventListener('click', () => {
6+
import('./other').then((module) => {
7+
module.other()
8+
})
9+
})
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function other() {
2+
console.log('other')
3+
}

examples/06-bundle-for-browser/scripts/run-build.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ async function build() {
66
await esbuild.build({
77
entryPoints: ['app/index.js'],
88
bundle: true,
9-
outfile: 'build/build.js',
9+
outdir: 'build',
1010
minify: true,
1111
sourcemap: true,
12+
splitting: true,
13+
format: 'esm',
1214
})
1315

1416
await fsPromises.copyFile('app/index.html', 'build/index.html')
17+
await fsPromises.copyFile('app/favicon.ico', 'build/favicon.ico')
1518
}
19+
1620
build()
1721

1822
const watcher = watch(['app/**/*'])

0 commit comments

Comments
 (0)