Bootstrapping in Angular
What is a Bootstrapping
Bootstrapping is a technique of initializing or loading our Angular application.
let’s walk through our code created in Create your First new Angular project and see what happens at each stage and how our AppComponent
gets loaded and displays “app works!”. The Angular takes the following steps to load our first view.
- Index.html loads
- Angular, Third-party libraries & Application loads
- Main.ts the application entry point
- Root Module
- Root Component
- Template
Index.html Loads First
Web apps need a starting point. Index.html
is usually the first page to load. Let us open the file and find out what it contains. You will find it under the src
folder.
There are no javascript files in the index.html
. Neither you can see a stylesheet file. The body of the files has the following HTML tag.
<app-root></app-root>
How do Angular loads ?. To Find out, let us build our application.
Building Application
To run our application, we use the Angular CLI command ng serve
or NPM command npm start
(npm start
command actually translates into ng serve
.)
ng serve
does build our application but does not save the compiled application to the disk. It saves it in memory and starts the development server.
We use ng build
to build our app. Open the command prompt and run the command. This will build and copy the output files to the dist
folder.
ng build
Use ng build --prod
to build and distribute the app for production. For testing/debugging use ng build
. The production build optimizes, minimize and uglify the code.
Now open the dist
and open the index.html
.
You can see that the compiler included five script files. They are runtime
, polyfills
, styles
, vendor
, & main
. All these files have two versions one is es5
& the other one es2015.
runtime.js:
Webpack runtime filepolyfills.js
– Polyfill scripts for supporting the variety of the latest modern browsersstyles.js
– This file contains the global style rules bundled as javascript file.vendor.js
– contains the scripts from the Angular core library and any other 3rd party library.main.js
– code of the application
These files are added by the Webpack module loader.
Full Article: Angular Bootstrapping Internal Working
No comments:
Post a Comment