Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@ngtools/webpack): fix compilation not working properly with webpack-dev-server #4009

Closed
wants to merge 5 commits into from
Closed

fix(@ngtools/webpack): fix compilation not working properly with webpack-dev-server #4009

wants to merge 5 commits into from

Conversation

ryanclark
Copy link

When using @ngtools/webpack with webpack-dev-server, the AoT compiler would use a program created from the last build, causing files not to compile unless the process was restarted or another build was triggered.

Creating a new program just before compilation from the old program to grab the latest source code fixes this.

Fixes #3084

…ack-dev-server

Fix files not compiling first time when using @ngtools/webpack with webpack-dev-server,
either the server would need to be restarted or another rebuild triggered before
updates would show.

Fixes #3084
@ryanclark
Copy link
Author

Also fixes #2576

@hansl
Copy link
Contributor

hansl commented Jan 15, 2017

@filipesilva please check this. We need to be aware of performance impacting PRs such as this one. We already rebuild the program and re-rebuild it a second time might be a problem.

@filipesilva
Copy link
Contributor

@hansl benchmark over master:

Angular-CLI Benchmark
Extra flags per benchmark: --aot
Iterations per benchmark: 5

=========================================
Base command: ng serve --no-progress
Comment: third rebuild time

Full command: ng serve --no-progress
Average time: 1396
Results: 1401,1385,1397,1392,1405

Full command: ng serve --no-progress --aot
Average time: 2895.6
Results: 2873,2935,2857,2963,2850

Benchmark execution time: 182722.018ms

Benchmark with these changes:

Angular-CLI Benchmark
Extra flags per benchmark: --aot
Iterations per benchmark: 5

=========================================
Base command: ng serve --no-progress
Comment: third rebuild time

Full command: ng serve --no-progress
Average time: 1456
Results: 1434,1579,1401,1417,1449

Full command: ng serve --no-progress --aot
Average time: 3484
Results: 3485,3451,3471,3469,3544

Benchmark execution time: 193738.856ms

So:

  • 4% increase on non-aot rebuilds
  • 20% increase on aot rebuilds

I think the change on non-aot is just variance since the code change doesn't even run outside of aot.

As far as the the PR is concerned, I don't think speed should be a major concern for --aot rebuilds really.

@filipesilva
Copy link
Contributor

@rynclark is this still a problem? @ngtools/webpack changed a lot in the last month so I wonder if this was fixed as well.

@randombk
Copy link

randombk commented Mar 2, 2017

I can confirm that this issue still occurs in 1.2.11. Applying this patch fixes the issue.

randombk added a commit to randombk/angular-cli that referenced this pull request Mar 2, 2017
  Update of angular#4009 by @rynclark to latest version of codebase.

  TypeScript caches the contents of source files within the program
  to minimize redundant compilation of non-changing code. This cache
  is not invalidated in @ngtools/webpack, causing two issues:
    1. When the watcher is triggered, the old version of the source
       is used. A second save is necessary for changes to take effect.
    2. When a change would result in a compilation error, the initial
       save will pass without errors. Subsequent saves, even saves
       containing fixes to the original error, will continue to fail
       with the original error. This is likely caused by TypeScript
       trying to compare any new programs against an invalid prior
       program state.

Signed-off-by: RandomBK <[email protected]>
@randombk
Copy link

randombk commented Mar 2, 2017

In hopes of getting this merged asap, I updated this patch to the new codebase and added some observations from my own investigation into this issue at #5164.

@filipesilva
Copy link
Contributor

Heya @rynclark @randombk, the original issue you were trying to solved seemed to be broken webpack configuration (#3084 (comment)).

I'm looking at this PR in relation to #5137 though, which seems to be exactly what you describe.

The changes in this PR break CI however, showing the following error:

ERROR in /tmp/angular-cli-e2e-11723-3750-1s602l2.d8uh0py14i/assets/webpack/test-app/app/main.aot.ts (3,34): Cannot find module './ngfactory/app/app.module.ngfactory'.)

This makes me think there's something missing in your solution.

@ryanclark
Copy link
Author

Not sure why it's breaking CI, it was working when created - haven't had the chance to update it to reflect any recent changes however.

This is why I created @ultimate/aot-loader - might be worth poking around there and seeing what we do differently from each other to get a solid solution.

@randombk
Copy link

@filipesilva The comment you linked does not help with this issue - I already had @ngtools/webpack in my config.

The issue continues to occur in 1.3.0, with webpack 2.4.1. Webpack no longer picks up changes in TypeScript code or angular templates. Multiple edits+saves are required before changes are registered.

My original PR (e2d8276) continues to work with the latest version, but after using it for a while, I noticed that only changes in TypeScript code are handled, while the issue persists with templates. This suggests that the real issue(s) is somewhere deeper in the codebase.

@clydin
Copy link
Member

clydin commented Feb 1, 2018

This should no longer be needed with the new Angular 5 compiler pipeline.

@clydin clydin closed this Feb 1, 2018
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Modifying component template in AOT mode has no affect only after restart
6 participants