1

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. ^_^

Alxpsr
  • 138
  • 10
  • Hey! Did you manage to make it work, so it won't compile the whole code? – Skeeve May 09 '19 at 13:05
  • 1
    @Skeeve Hi there! If I'm not mistaken, I did it like this: 1) Delete mask from `tsconfig.include` 2) Add directly TS entrypoints to `tsconfig.files` – Alxpsr May 14 '19 at 10:01

1 Answers1

0

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.

Sachin Gupta
  • 4,981
  • 3
  • 16
  • 32
  • Yes, thank you. But i don't understand why ts-loader compiler step by step by imports, when ngtools compile whole project. – Alxpsr Nov 11 '18 at 07:47
  • Its not the ngtools, but the Angular compiler plugin that you are using which makes the difference. The tsloader also compiles the complete project, ignoring the HTML error, such as incorrect tag ending, function call. – Sachin Gupta Nov 11 '18 at 09:20
  • The problem is that this plugin is compiling EVERYTHING for some reason. It compiles sibling modules, it compiles tests. Also, it reports about errors that don't exist at runtime. They don't exist at all. And it wouldn't be a problem if this compiler sticks to what it supposed to compile according to `entryModule` – Skeeve May 09 '19 at 13:21