Search⌘ K
AI Features

Simplified JavaScript Imports

Explore how to simplify JavaScript imports by using Parcel with Transcrypt. Understand configuring your HTML entry point, employing Node.js require() for module loading, and managing bundled files. This lesson helps you integrate Parcel's bundling and server features to streamline Python-based front-end web applications.

Configuring Parcel

We do need to make one small change to our HTML file. Since our entire application will be compiled and bundled as a single resource, we want the application entry point to be our HTML file. So rather than directly specifying the entry point as our Python code, the Python files will get pulled in from the HTML file instead.

So let’s make that small change by indicating our source Python file instead of the generated JavaScript file:

Lines 4 to 7 in react_hello4.html is changed to the following line:

HTML
<script src="react_hello4.py"></script>

Using require

Another change we can now make, since we are using Parcel, is to use the require() module loader function built into Node.js, instead of using JavaScript functions to manage our ...