![ECMAScript Cookbook](https://wfqqreader-1252317822.image.myqcloud.com/cover/58/36700058/b_36700058.jpg)
上QQ阅读APP看书,第一时间看更新
How to do it...
- Open your command-line application and navigate to the directory containing the 02-creating-client-bundles package.
- Start the Python HTTP server.
- Create a file named index.html (copied from the Nesting modules under a single namespace recipe in Chapter 1, Building with Modules):
<html> <head> <meta charset='UTF-8' /> </head> <body> <h1>Open your console.</h1> <script type="module"> import { main } from './main.js'; main(); </script> </body> </html>
- Add a nomodule script tag to the body after the existing module in the <script> tag:
<body> <h1>Open your console.</h1> <script type="module"> import { main } from './main.js'; main(); </script> <script nomodule type="text/javascript"src="bundle.js"></script> </body>
- Run the webpack build command:
./node_modules/.bin/webpack --config webpack.config.js
- Open your ES module-compatible browser, open the Developer tools to the Network tab, and visit the URL:
http://localhost:8000/. - You should see the individual files loaded by the browser:
![](https://epubservercos.yuewen.com/C944E7/19470395501577006/epubprivate/OEBPS/Images/306a1e80-618f-4911-bb2c-a949f4225e7b.png?sign=1738937450-3Bqq2lCz8DkGJiYYPlZJpWMJEyY9eUD6-0-523e8c44681ed08d0d4bee762a715655)
Open a browser that isn't compatible with ES modules. Open the Developer tools to Network and visit the URL:
http://localhost:8000/.
- You should see the bundle.js file loaded instead: