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

Angular: Use ngtools/webpack instead of at-loader #7231

Closed
wants to merge 13 commits into from

Conversation

wmarques
Copy link
Contributor

@wmarques wmarques commented Mar 5, 2018

It's better to lazy load modules to reduce the main bundle size and avoid giving the user data he will probably never need.

In order to make the lazy loading work with webpack we have two choices:

  • Use the angular-router-loader for the dev config and @ngtools/webpack for prod (with AOT)
  • Use @ngtools/webpack everywhere

For consistency and simplification I chose to use @ngtools/webpack everywhere except for the test configuration, I couldn't make it work... But I saw that we were using a fork of the "official" istanbul-instrumenter-loaderso I put in our dependencies the official loader and not the fork which doesn't seems maintained anymore.

We can discuss this of course, I didn't see much performance issues using @ngtools/webpack in development mode.

  • Please make sure the below checklist is followed for Pull Requests.

  • Travis tests are green

  • Tests are added where necessary

  • Documentation is added/updated where necessary

  • Coding Rules & Commit Guidelines as per our CONTRIBUTING.md document are followed

@wmarques
Copy link
Contributor Author

wmarques commented Mar 5, 2018

If you have any hints on the SyntaxError: Unexpected token importI'm having with protractor... It doesn't seems related to the PR

EDIT: fixed, had to create a tsconfig especially for protractor 😢

@@ -40,6 +41,10 @@ module.exports = (options) => ({
},
module: {
rules: [
{
test: /(?:\.ngfactory\.js|\.ngstyle\.js|\.ts)$/,
use: [ '@ngtools/webpack' ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

brave move 😉 😜

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha yes ! Please try if you see any performance issues I'll rollback of course 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah sure 👍
Did you find any good performance change?
This also means that we will have to wait for angular-cli release cycle. v6 - ivy promises a lot let us see

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do some tests to see the build time but it seemed pretty much the same...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what matters is the time to compile when in hot reload mode for any changes to a file

Copy link
Member

@sendilkumarn sendilkumarn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 awesome so we do have lazy loading in V5

🎉 🎆

@@ -64,6 +69,11 @@ module.exports = (options) => ({
]
},
plugins: [
new AngularCompilerPlugin({
mainPath: utils.root('src/main/webapp/app/app.main.ts'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<%= MAIN_SRC_DIR %>

@@ -61,7 +61,7 @@ module.exports = (WATCH) => ({
test: /src[/|\\]main[/|\\]webapp[/|\\].+\.ts$/,
enforce: 'post',
exclude: /node_modules/,
loader: 'sourcemap-istanbul-instrumenter-loader?force-sourcemap=true'
loader: 'istanbul-instrumenter-loader?force-sourcemap=true&esModules=true'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you change this to use syntax ?

"lint": [{
"project": "../../../tsconfig.json"
},
"lint": [
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you try to lint this like the deleted line above ?

@@ -78,6 +78,7 @@
"html-loader": "0.5.0",
"html-webpack-plugin": "3.0.0",
"husky": "0.14.3",
"istanbul-instrumenter-loader": "3.0.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3.0.0 doesn't support webpack 4 right ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't have issue about this...

{
test: /\.ts$/,
loaders: [
'angular2-template-loader',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this dependency also removed from package.json ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope because we need it in the webpack.test :(

@@ -363,7 +363,6 @@ const expectedFiles = {
`${CLIENT_TEST_SRC_DIR}spec/helpers/mock-state-storage.service.ts`,
`${CLIENT_TEST_SRC_DIR}spec/helpers/spyobject.ts`,
`${CLIENT_TEST_SRC_DIR}spec/test.module.ts`,
'tsconfig-aot.json',
'tsconfig.json',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tsconfig.e2e ?

@wmarques
Copy link
Contributor Author

wmarques commented Mar 5, 2018

Seems that I have an issue with the interceptors who are not shared in the lazy loaded module. I think the cause is maybe the ng-jhipster library who exports the HttpClientModule, but this module should be imported only once in the app

@sendilkumarn
Copy link
Member

@wmarques WDYT about this?

Split this PR into 2, one to migrate to ngtools-webpack other one for lazy loading

The first one will fix the yarn start issue.

@wmarques
Copy link
Contributor Author

wmarques commented Mar 5, 2018

@sendilkumarn Yep LGTM :) I'm also investigating the HttpClient issues. So should we close this PRand i'll do two others ?
But in the lazy loading PR, should I use the ng-tools/webpack ? Or i keep the awesome-typescript-loader ?

@wmarques
Copy link
Contributor Author

wmarques commented Mar 5, 2018

@sendilkumarn this PR will be about the ngtools usage, I'll create a new one for the lazy loading if that's ok for you

@sendilkumarn
Copy link
Member

@wmarques yeah sure no issues at all. Just split it. I think @ngtools won't break now. So it can be merged and lazy loading we can check and merge

@sendilkumarn
Copy link
Member

pinging @deepu105 at-loader is not working here due to some issues. It is better time to switch to @ngtools WDYT ? I remember last time, you don't want to move to @ngtools

@wmarques wmarques changed the title Angular: Lazy load Admin Module Angular: Use ngtools/webpack instead of at-loader Mar 5, 2018
@wmarques wmarques mentioned this pull request Mar 5, 2018
4 tasks
@sendilkumarn
Copy link
Member

@wmarques did you refactor the PR ?

@deepu105
Copy link
Member

deepu105 commented Mar 6, 2018

@sendilkumarn @wmarques last time I didn't want to switch as it was slow in development, please test with some 10-15 entities. Each code change was taking so long to compile while running yarn start as everything was being recompiled instead of incremental changes. IF that issue no longer exists and the difference in performance while using Yarn start is very minimal then I'm ok to switch

Could you guys post some stats pre and post this change when using Yarn start

@wmarques
Copy link
Contributor Author

wmarques commented Mar 6, 2018

Yep I'll try with a big project. Do you have a repo where I can test this kind of config ?
I don't have time tonight but tomorrow I'll check this and refactor the PR to remove the lazy loading part. Thanks

@deepu105
Copy link
Member

deepu105 commented Mar 6, 2018 via email

@wmarques
Copy link
Contributor Author

wmarques commented Mar 7, 2018

I refactored the PR it should now only contains the ngtools part ! I'm testing it with a big application to check performances.

EDIT: so I tried with the sample app in travis folder, and the dev workflow is very slow with @ngtools, as @deepu105 said it seems to recompile everything and each refresh takes too much time (ie: 17010ms chunk assets processing), maybe in v6 it will be faster...

@deepu105 deepu105 added the v5 label Mar 9, 2018
@sendilkumarn
Copy link
Member

can we try with ts-loader if we can ? It was also migrated to v4.

@pascalgrimaud
Copy link
Member

Just finished to align the registry with JHipster v5: jhipster/jhipster-registry#251

@wmarques @sendilkumarn : do you think we should do the same for the registry too ?

@deepu105
Copy link
Member

deepu105 commented Mar 9, 2018 via email

@wmarques
Copy link
Contributor Author

@sendilkumarn You mean using ts-loader for the dev mode ? Or for dev and prod ?

@deepu105
Copy link
Member

@wmarques @sendilkumarn seems like migrating to webpack 4 didn't give us any performance improvements and our tests seems to be slower now, so I'm worried about this so can we first do a benchmark?

@deepu105
Copy link
Member

@wmarques also take a look at s-panferov/awesome-typescript-loader#497

@deepu105
Copy link
Member

Btw I can really see webpack performance improvement in React :)
Build time down to 15 secs with ts-loader, gonna try to make it even faster

@deepu105
Copy link
Member

So with ts-loader, cache-loader, thread-loader and fork-ts-checker-webpack-plugin I got build times of 12 secs for React with few entities. The yarn start compilation is very fast as well, ~10s fisrt run and ~3s for a change, also everything including yarn start works so we can try the same for Angular as well and compare to ngtools for performance.

@deepu105
Copy link
Member

@wmarques do you still want to do this? if so please benchmark this against the current setup with ts-loader first plz

@jdubois jdubois added this to the 5.0.0-beta.0 milestone Apr 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants