Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 Production build file is large

Tags:

angular

I have just created a new angular app using "ng new appName" and put in some buttons (from ng-bootstrap). I wanted to try to deploy to aws to check it out. However, when I run ng build --prod, the one of the dist file (vendor.a9e57aafdd6abc88b94a.bundle.map) generated is 7.7mb. Here is a screen shot of the files. What is the best way to resolve this issue so the user does not have to download that big of a file upon load?

screen shot

like image 527
user172902 Avatar asked Feb 01 '17 08:02

user172902


2 Answers

You are showing the file size of a .map file. A mapping file is used to let for instance the browser development tools map your compiled javascript to separate typescript files, which makes debugging easier. You've build this with a slightly older version of angular-cli. If you do not want these sourcemaps just build with a --no-sourcemap option, or upgrade to the latest version, where --prod will automatically disable sourcemapping. This will also greatly increase build times.

For a production build you only need your index.html, the css and js files, and your assets folder (+ favicon). If you manage to set up your webserver even better to serve static gzip files, you can even just place the js.gz and css.gz files on your webserver, and these will be served, which will increase performance even more.

Your users will not download a sourcemap file, unless you place it there, and they open up their browser console. This will give them insight in how you build your app. This can be unwanted

like image 199
Poul Kruijt Avatar answered Sep 22 '22 19:09

Poul Kruijt


How To Keep Angular Deployment Size Small :

Take a look at the structure of my project .

Home page size is 922kb . demo

like image 37
unos baghaii Avatar answered Sep 23 '22 19:09

unos baghaii