The dimensions of my Angular app have begun to unexpectedly expand

Currently in the process of developing an Angular application, I've encountered a frustrating issue. Each time I refresh the app using ng serve, the loading time seems to increase gradually. It can now take up to 10 seconds for changes to reflect in the browser (tested on Chrome, Firefox, and Safari). Initially, I dismissed it as a browser problem, but upon further investigation, I discovered that the size of main.js during development is a staggering 27 MB. This puzzles me because I have worked on larger projects without facing such issues before. Even after running ng build --prod, the output remains over 8 MB, which seems excessive.

I could resort to rolling back using git, but I'm hopeful there's a more effective way to pinpoint the root cause of this sudden file size surge. Any suggestions on where to start would be greatly appreciated.

Here's the output of ng version:

Angular CLI: 7.0.6
Node: 8.11.2
OS: darwin x64
Angular: 7.1.0
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.10.6
@angular-devkit/build-angular      0.10.6
@angular-devkit/build-ng-packagr   0.10.6
@angular-devkit/build-optimizer    0.10.6
@angular-devkit/build-webpack      0.10.6
@angular-devkit/core               7.0.6
@angular-devkit/schematics         7.0.6
@angular/cli                       7.0.6
@ngtools/json-schema               1.1.0
@ngtools/webpack                   7.0.6
@schematics/angular                7.0.6
@schematics/update                 0.10.6
ng-packagr                         4.4.0
rxjs                               6.3.3
typescript                         3.1.6
webpack                            4.19.1

Below is my current package.json:

{
  "name": "website",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^7.1.0",
    .
    . here goes numerous dependencies listed from bootstrap to zone.js...
    .
  },
  "devDependencies": {
    .
    . likewise, various dev dependencies listed from codelyzer to typescript...
    .
  }
}

Another point to note:

Recently, I moved a portion of the code base into an additional module with the intention of creating a separate NPM package eventually. While this step was new to me, the segment involved consists solely of TypeScript classes without any GUI elements, so it shouldn't be the source of the issue.

Answer №1

When integrating Bootstrap into my project, I struggled due to following incorrect instructions. However, after taking advice from a helpful answer on How to use Bootstrap 4 with SASS in Angular, I was able to successfully resolve the issues I was facing.

Key points that made a difference:

It's crucial to import the scss files instead of the css files in the angular.json:

"styles": [
  "node_modules/bootstrap/scss/bootstrap.scss"
]

For my specific case, I only imported necessary files in styles.scss:

@import "~bootstrap/scss/functions";
@import "~bootstrap/scss/variables";

Prior to this adjustment, I had mistakenly imported the entire Bootstrap scss file in this section. This caused Angular CLI to import the full Bootstrap content multiple times whenever a component scss imported my main.scss.

Resulting impact:

The table below illustrates the significant reduction in file size before and after implementing these corrections:

Command          |  before   |  after
---------------------------------------
ng build         |  27.1 MB  |  2.87 MB
ng build --prod  |   8.1 MB  |  1.54 MB

I am hopeful that sharing my experience can assist others facing similar challenges.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Experiencing difficulties while running the npm internationalize command

Package Details { "name": "m.zbor.md", "version": "1.0.0", "description": "Mobile version of Zbor.md website", // more package details... } Typescript Configuration { "compilerOptions": { "target": "es5", "module": "commonjs", // m ...

Determining the parameter type of an overloaded callback: A comprehensive guide

I am currently working on creating a type-safe callback function in TypeScript with a Node.js style. My goal is to define the err parameter as an Error if it exists, or the data parameter as T if not. When I utilize the following code: export interface S ...

There was a DOMException in Angular because the transaction is not active when trying to execute 'getAll' on 'IDBObjectStore'

private get ctxMessage() { const messageTransaction = this.db.transaction('messages', 'readwrite'); const messageStore = messageTransaction.objectStore('messages'); return { messageTransaction, messageStore }; } ...

Tips for incorporating SectionList sections in React Native using an array

I am working with an array of objects named movies (const movies = movie[]). Each movie object includes properties like name, description, date and duration. movie: { name: string; description: string; date: Date; duration: number } My ...

Using currency symbols in Angular 2

I'm currently in Australia and trying to display some currency values. I have the following code: {{ portfolio.currentValue | currency : 'AUD' : true : '4.0' }} However, the result I am getting is A$1,300,000. Is there a way to c ...

Tips for displaying only the initial 15 characters of a text value

The content extracted from a .ts file is being displayed on the home.html page. I am aiming to display only the initial 15 characters followed by 3 dots (...). Despite my efforts, the following code snippet is not functioning as expected: home.html < ...

Express Server Providers for Angular 17's Server-Side Rendering

I attempted to share my request and response object with the Angular application by defining Providers in the "server.ts" file. However, when injecting them into app.component, they always appear undefined regardless of whether I am in the server or clie ...

Experiencing Problems with Bot Framework Authentication - Receiving HTTP 401 Error

My current project involves creating a chat bot using the Microsoft Bot Framework and SDK in TypeScript. I am working on implementing user authentication for the bot to interact with Azure DevOps on behalf of users. While testing authentication in Azure Po ...

Is there a way to optimize app speed in Angular2 by importing CommonModule and RouterModule in a centralized location?

I find myself constantly importing these two modules in almost every component: import { CommonModule } from '@angular/common'; import { RouterModule } from '@angular/router'; Is there a way to import them only once in the global app. ...

Guide to Conditionally Importing a Module in Angular

I am currently developing a module for Search integration. Instead of directly importing the SearchModule inside my app.module.ts file, I would like to implement a method where an API is called and the SearchModule is imported based on the API response. @N ...

Similar to TypeScript's `hasOwnProperty` counterpart

When working with TypeScript objects, is there a way to loop through a dictionary and set properties of another dictionary similar to how it is done in JavaScript? for (let key in dict) { if (obj.hasOwnProperty(key)) { obj[key] = dict[key]; } } If ...

The Angular ngFor directive seems to be failing to display the items within the array, even though accessing the items directly by using array[index

I've come across a strange issue with a simple program I'm working on. I want to display a list of numbers using an array, but when I try to use *ngFor in Angular, the elements don't render. However, if I manually reference each element in t ...

How can I trigger a click event with Ionic's ion-toggle and radio-group components

I am currently using Ionic3 and I would like to implement an HTML element (ion-toggle and radio-group) that triggers a JavaScript function upon clicking. As you can observe below, I have included an attribute ng-click as per the guidance provided here, bu ...

Utilizing TypeScript code to access updatedAt timestamps in Mongoose

When querying the database, I receive the document type as a return. const table: TableDocument = await this.tableSchema.create({ ...createTableDto }) console.log(table) The structure of the table object is as follows: { createdBy: '12', cap ...

How can one efficiently update post statuses in Ionic 4 without having to constantly reload or refresh the webpage?

I have created a dynamic list of posts, each with a "like" and a "comment" button. The issue I'm facing is that whenever I click on the like button, I have to manually refresh the page for the changes to appear. One approach I considered was incorpor ...

What could be causing the elements in my array to appear as undefined?

https://i.stack.imgur.com/ze1tx.png I'm stuck trying to understand why I can't extract data from the array. const usedPlatformLog: Date[] = [] users.forEach(el => { usedPlatformLog.push(el.lastUsed) }) console.log(usedPlatformLog) // disp ...

Strategies for adding elements to a FormArray in Angular 4

I am currently working on a dynamic Angular form that displays like this. <form [formGroup]="myForm"> <div *ngFor="let Repo of Repos;"> <fieldset> <legend>{{Repo.name}}</legend> ...

Loading CSS files conditionally in Angular2's index.html

Currently, my index.html page features a dark theme: <base href="/"> <html> <head> <title>XXX</title> </head> <body> <link rel="stylesheet" type="text/css" href="assets/dark_room.css"> <my-app ...

Unable to locate module: The system was unable to find the specified module '@angular-devkit/build-angular/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js'

After encountering an error with Mat Dialog boxes close button not working on IOS devices (refer to Stack Overflow), I decided to downgrade my Angular project from version 14.0.0 to 13.0.0. I followed a solution provided in another Stack Overflow thread. H ...

Update ng-Bootstrap ToDate field by removing the date when selecting a fromDate

Is there a way to clear the date from the toDate input field while selecting a date from the fromDate input field in ng-bootstrap? <form class="row row-cols-sm-auto" *ngIf="showDateRangeImp"> <div class="col-12" ...