File tree Expand file tree Collapse file tree 10 files changed +24
-7
lines changed
Expand file tree Collapse file tree 10 files changed +24
-7
lines changed Original file line number Diff line number Diff 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 >
Original file line number Diff line number Diff line change 1+ export function sayHi ( ) {
2+ console . log ( "Let's bundle this code" )
3+ }
Original file line number Diff line number Diff line change 1- export function sayHi ( ) {
2- console . log ( "Let's bundle this code" )
3- }
1+ import { sayHi } from './sayHi.js'
2+ export { sayHi }
Original file line number Diff line number Diff line change 11{
22 "name" : " browser-modules" ,
3- "type" : " module" ,
43 "scripts" : {
54 "start" : " http-server app -p 3000"
65 },
Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change 11import { sayHi } from './utils.js'
22
33sayHi ( )
4+
5+ document . getElementById ( 'button' ) . addEventListener ( 'click' , ( ) => {
6+ import ( './other' ) . then ( ( module ) => {
7+ module . other ( )
8+ } )
9+ } )
Original file line number Diff line number Diff line change 1+ export function other ( ) {
2+ console . log ( 'other' )
3+ }
Original file line number Diff line number Diff 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+
1620build ( )
1721
1822const watcher = watch ( [ 'app/**/*' ] )
You can’t perform that action at this time.
0 commit comments