@ngtools/webpack does not build by entrypoint imports

289 views Asked by At

I use @ngtools/webpack directly in angular-app (withou angular-cli) and i got unexpected behavior. Aot plugin build all ts-files in project, but some files not imported by entrypoint file (main.ts). For expample - ts-loader build only files that find by imports in entrypoint file (main.ts). This is bug or feature?

I created mini-repo: https://github.com/alxpsr/ngtools-unexpected Run npm run build:aot and you got an error. But if you run npm run build:tsloader - the build will not have an error.

If this is not a bug, please tell me what the difference between this two builds?

P.S. I know about files and include option in tsconfig.json and i can specify files more clearly there. I want to understand the differences between these two builds. ^_^

1

There are 1 answers

3
Sachin Gupta On

Both the builds are different. When building using AOT, the code is compiled using the angular compiler. It compiles all your code before deploying so the client-browser doesn't have to do much work. For example, if you have called a function in HTML, but don't have the function defined in your component, the Angular Compiler will give you error while building the app itself.

On the other hand, when you build using tsloader, the build succeeds, but the app breaks on runtime when you encounter such an error.