Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSerdar Halac
15,259 PointsCan someone explain all those changes since the intro to react videos? Lots of unexplained things
In the intro to react course, we use script tags to include app.js in index.html
But in this course, I don't see a single reference to app.js in index.html, no import no nothing.
In the intro to react course, the script tags included references to react, app.js, babel, etc...
In this course, there isn't even a reference to a bundle.js or anything in the tags! Just the id, but it seems weird to me. How does the HTML know to use app.js and react as scripts?? Where does it go?
Is something going on in the background that connects the app.js file to the index.html file?
What changed since the intro to react course? Also, why is the file called app.js and not app.jsx? This is what was used in the past. And why are we importing react in results, searchform, AND app.js? Isn't that wasteful? Why not import in app.js only since app.js imports the components anyways? Wouldn't that just end up with a single file that uses everything once? And what is export default?
3 Answers
Seth Kroger
56,413 PointsAh yes, it's creating what's called a Progressive Web App (PWA), which allows a browser to pre-load the site and even allow it to be used offline. The manifest <link>
gives supporting browsers the information necessary to load the scripts.
Seth Kroger
56,413 PointsCreate React App configures a tool called webpack to build and package up the app. It will package up all the JavaScript files into a file called bundle.js that you should see included in the index.html file. CRA will configure it so app.js is considered the entry-point, or starting code to run for the bundle.
Serdar Halac
15,259 PointsThanks for answering. Here is the index.html file in the public folder:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<!--
manifest.json provides metadata used when your web app is added to the
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
I don't really see a reference to app or bundle.js?
Serdar Halac
15,259 Points<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"><meta name="theme-color" content="#000000"><link rel="manifest" href="/manifest.json"><link rel="shortcut icon" href="/favicon.ico"><title>React App</title><link href="/static/css/main.ca837a83.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script type="text/javascript" src="/static/js/main.990fc8d6.js"></script></body></html>
This is the index.html file in the static folder, in the build file, there is a src script tag for a main.990fc8d6.js, is that it? If so, why is there no reference in the public folder html but there is a reference in the build static folder?
Serdar Halac
15,259 PointsSerdar Halac
15,259 PointsThansk for your input. By the way, I was able to solve my question with the create-react-app docs, which state:
But even better, here is Dan Abramov, the co-creator of create-react-app himself explaining it: