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

feat: use import() construct via ng-router-loader@2.0.0 #1387

Merged
merged 3 commits into from
Jan 23, 2017

Conversation

shlomiassaf
Copy link
Contributor

Support the Dynamic import proposal [TC39 Stage 3] as a loader (codegen).
The import() construct is supported in webpack from 2.1.0-beta28

"async-system" is deprecated in webpack 2 and removed in webpack 3.

Moving to 2.0.0 requires a subtle change in the TS loader order.

Dev's that just upgrade the packages will have some trouble locating this change in the configs so we might expect some noise

Reason for change:
Typescript transform import(...) syntax into something else.
To use ng-router-loader with async-import code generator the ng-router-loader must
run AFTER the TS compiler (e.g: awesome-typescript-loader), that is in a lower index in the loaders array. If it runs before, TS will see the import(... expression and will convert it into invalid code.

This change also requires the code generators to emit ES5 code, all codegen's now emit ES5 code.

SEE: microsoft/TypeScript#12364

fix: upgrade webpack-dll-bundles-plugin
Copy link
Contributor

@colinskow colinskow left a comment

Choose a reason for hiding this comment

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

I was wondering about that the other day. It appears that previously the modules were loaded on startup, rather than on navigating to the lazy routes.

Looks good to me.

@shlomiassaf
Copy link
Contributor Author

shlomiassaf commented Jan 18, 2017 via email

@colinskow
Copy link
Contributor

How would you configure it to load the chunks on route change?

@shlomiassaf
Copy link
Contributor Author

shlomiassaf commented Jan 18, 2017 via email

@joshwiens
Copy link
Contributor

Outside of Patrick's approval, we need to get decent documentation around this with all the other routing docs. Most of the users of this starter don't follow TypeScript issues / TC-39 like we do.

@shlomiassaf
Copy link
Contributor Author

Worth noting that in 2.0.0 you had to move the loader to the top only if you wanted to use asyn-import, that is, use the new import() dynamic module loading construct.

In 2.1.0 it is required for all use cases since I switched to JS AST, if you sent TS to the loader it will fail...

It doesn't make sense to use the TS compiler here since angular can run on raw JS code

 The definition of the `*.ts` loader is getting more complex.
 We need AOT compliance so we use `angular2-template-loader`
 We need lazy loading so we use `ng-router-loader`
 And of course, we need to compile TS to JS, `awesome-typescript-loader`

 We can't explain all that in the configuration file but we can use Webpack 2 new loader syntax and use objects instead of literal string to configure the loaders.
@shlomiassaf
Copy link
Contributor Author

@d3viant0ne, last commit reasoning

The definition of the *.ts loader is getting more complex.
We need AOT compliance so we use angular2-template-loader
We need lazy loading so we use ng-router-loader
And of course, we need to compile TS to JS, awesome-typescript-loader

We can't explain all that in the configuration file but we can use Webpack 2 new loader syntax and use objects instead of literal string to configure the loaders.

@shlomiassaf
Copy link
Contributor Author

@d3viant0ne Please review https://github.com/AngularClass/angular2-webpack-starter/wiki/Routing-and-Lazy-loading-@NgModules

Comments are welcome

@shlomiassaf
Copy link
Contributor Author

@gdi2290 make a quick review on this one, it's a block for another PR and the current loader's version (2.1.0) has bug fixes and improvements that we need to push into the starter.

@colinskow
Copy link
Contributor

@shlomiassaf I made some documentation on lazy loading here:
https://github.com/AngularClass/angular2-webpack-starter/pull/1378/files#diff-04c6e90faac2675aa89e2176d2eec7d8R251

You could probably take the first part of that.

@joshwiens joshwiens merged commit 35b48e5 into PatrickJS:master Jan 23, 2017
awcodify pushed a commit to awcodify/d3-angular-4 that referenced this pull request Aug 28, 2017
* feat: use import() construct via ng-router-loader@2.0.0
fix: upgrade webpack-dll-bundles-plugin

* refactor: verbose ts loader definition

 The definition of the `*.ts` loader is getting more complex.
 We need AOT compliance so we use `angular2-template-loader`
 We need lazy loading so we use `ng-router-loader`
 And of course, we need to compile TS to JS, `awesome-typescript-loader`

 We can't explain all that in the configuration file but we can use Webpack 2 new loader syntax and use objects instead of literal string to configure the loaders.
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.

4 participants