Angular 11 Exclude Unused Classes

279 views Asked by At

I'm trying to compile a large Angular 11 web application. This application has some files that are code generated.

Here is an example...

File:

models.ts

Contents:

export class A {
  ... // No reference to B or C
}

export class B {
  ... // No reference to A or C
}

export class C {
  ... // No reference to A or B
}

Elsewhere in my code I am referencing class A like so:

import { A } from './models.ts'

I am finding that the final build output of my project also includes classes B and C even though they aren't used anywhere and this is causing my bundle sizes to increase dramatically. Obviously, this is an overly simplified example but in my project some these files actually contain over 6k lines of code but are largely unused for this project. They are used in another project which shares a lot of the same code.

To be clear, I am running a production build with these relevant flags:

"optimization": true,
"aot": true,
"buildOptimizer": true

I feel like I am missing something fundamental here. Do I need to separate these classes into different files? How do I ensure that these unused classes aren't included in the output of my prod build?

0

There are 0 answers