Title: @ngtools/webpack feature request: support code splitting by third parties · Issue #4541 · angular/angular-cli · GitHub
Open Graph Title: @ngtools/webpack feature request: support code splitting by third parties · Issue #4541 · angular/angular-cli
X Title: @ngtools/webpack feature request: support code splitting by third parties · Issue #4541 · angular/angular-cli
Description: This is a feature request. I'd like to start discussion around @ngtools/webpack supporting code splitting by third party libs (including ui-router-ng2). Currently the code splitting support in @ngtools/webpack has a soft dependency on @a...
Open Graph Description: This is a feature request. I'd like to start discussion around @ngtools/webpack supporting code splitting by third party libs (including ui-router-ng2). Currently the code splitting support in @ngt...
X Description: This is a feature request. I'd like to start discussion around @ngtools/webpack supporting code splitting by third party libs (including ui-router-ng2). Currently the code splitting support in ...
Opengraph URL: https://github.com/angular/angular-cli/issues/4541
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"@ngtools/webpack feature request: support code splitting by third parties","articleBody":"This is a feature request. \r\n\r\nI'd like to start discussion around `@ngtools/webpack` supporting code splitting by third party libs (including `ui-router-ng2`). \r\n\r\n\r\nCurrently the code splitting support in `@ngtools/webpack` has a [soft dependency on `@angular/router`](https://github.com/angular/angular/blob/7a4c25535d79db6a2ecc49972594bc041791c142/modules/%40angular/compiler-cli/src/ngtools_impl.ts#L18-L21).\r\n\r\nMy understanding is that:\r\n\r\n- `@ngtools/webpack` loader [invokes `__NGTOOLS_PRIVATE_API_2.listLazyRoutes()`](https://github.com/angular/angular-cli/blob/f2f02a6c8122430ec2375610a5ecdb9c1383e02a/packages/%40ngtools/webpack/src/plugin.ts#L401-L408)\r\n- `listLazyRoutes` finds lazy routes:\r\n - [References the DI token `ROUTES`](https://github.com/angular/angular/blob/7a4c25535d79db6a2ecc49972594bc041791c142/modules/%40angular/compiler-cli/src/ngtools_impl.ts#L65) found in `@angular/router`\r\n - statically analyzes the application.\r\n - [checks each `NgModule` for provided `ROUTES`](https://github.com/angular/angular/blob/7a4c25535d79db6a2ecc49972594bc041791c142/modules/%40angular/compiler-cli/src/ngtools_impl.ts#L136-L141)\r\n - [Checks each route for `loadChildren`](https://github.com/angular/angular/blob/7a4c25535d79db6a2ecc49972594bc041791c142/modules/%40angular/compiler-cli/src/ngtools_impl.ts#L195-L210) and adds to the list of lazy routes.\r\n - returns lazy routes\r\n- [processes lazy routes](https://github.com/angular/angular-cli/blob/f2f02a6c8122430ec2375610a5ecdb9c1383e02a/packages/%40ngtools/webpack/src/plugin.ts#L410-L426), redirecting imports to `.ngfactory.ts` and doing webpack magic\r\n\r\n\r\n# Goal\r\n\r\nI think the goal should be to eliminate the dependency on `@angular/router` and provide a router agnostic mechanism for third parties to supply code splitting information.\r\n\r\nToday, UI-Router supports code splitting using `@ngtools/webpack` by importing the `ROUTES` token from `@angular/router`, [then providing the ui-router states as that DI token](https://github.com/ui-router/ng2/blob/3c043dd2c38189488cf3748b1c46fc19bf5f5603/src/uiRouterNgModule.ts#L23), i.e., `{ provide: ROUTES, useValue: module.states, multi: true }`. However, this forces ui-router to have a dependency on `@angular/router`. It also forces ui-router to emulate the structure of `@angular/router` by adding a `loadChildren` property.\r\n\r\n# Proposal 1\r\n\r\nMake the DI token configurable by `@ngtools/webpack`. \r\n\r\nDo not reference the token from `@angular/router` in `ngtools-impl.ts`, but pass the token in. UI-Router users could configure this somehow to use the `STATES` token, for example.\r\n \r\nThis proposal is rather limited in its usefulness. Only one library could support lazy loading + code splitting in a given app.\r\n\r\n# Proposal 2\r\n\r\nMove and/or rename the DI token out of `@angular/router`\r\n\r\nPerhaps the DI token could be moved to `@angular/compiler-cli`, `@angular/common`, or `@angular/core`. This eliminates the need to depend on `@angular/router`. Additionally, move the token to its own ES6 module. Today, importing the `ROUTES` token from `@angular/router` brings in unrelated symbols from `@angular/router` into the ui-router bundle even using rollup.\r\n\r\nThis proposal still conceptually ties lazy loading to the `@angular/router`. All terminology and code analysis assumes that lazy loading code processes `@angular/router` routes. Third parties have to emulate the router's structure.\r\n\r\n# Proposal 3\r\n\r\nIntroduce a routing-agnostic token such as `ANALYZE_FOR_LAZY_LOAD`. \r\n\r\nEither `@angular/router` or third parties should provide lazy load and code splitting information using this token. I propose instead of providing an array of specifically structured objects such as `ROUTES` or `STATES`, that only the lazy load information need be provided, i.e.:\r\n\r\n```js\r\n{ \r\n provide: ANALYZE_FOR_LAZY_LOAD,\r\n useValue: [ \r\n './child1/child1.module#Child1Module', \r\n './child2/child2.module#Child2Module' \r\n ]\r\n}\r\n```\r\n\r\nThe `@angular/router` would then provide the module's lazy load information by doing something like:\r\n\r\n```js\r\nconst lazyRoutes = ROUTES.map(x => x.loadChildren).filter(identity);\r\nconst provider = { provide: ANALYZE_FOR_LAZY_LOAD, useValue: lazyRoutes, multi: true };\r\n```\r\n\r\nThe knowledge about the lazy load declaration object (i.e., what the `loadChildren` property means on a route) is moved from `@angular/compiler-cli` to the library that owns that structure (i.e., the `@angular/router`).\r\n\r\nOf these three proposals, this one is my favorite as it separates concerns nicely and provides a clear mechanism for lib authors to use. \r\n\r\n\r\n","author":{"url":"https://github.com/christopherthielen","@type":"Person","name":"christopherthielen"},"datePublished":"2017-02-08T22:17:44Z","url":"https://github.com/angular/angular-cli/issues/4541"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:2b131c72-abbe-81ae-d03f-3b48cf300e11 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8168:A99C2:C391D2:FC75D1:6B00EC0B |
| html-safe-nonce | e40a27fe88c5035808006ff01d51a2c903b6cd27a54f0a20ecae3263ce73fa97 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MTY4OkE5OUMyOkMzOTFEMjpGQzc1RDE6NkIwMEVDMEIiLCJ2aXNpdG9yX2lkIjoiODg5Mjk5NDkwMzYwOTUwMjczMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | aaa93bd438d022258fafee10d9a7966a052dac15138ae9b740d8c818e4092a6d |
| hovercard-subject-tag | issue:206342447 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular-cli/4541/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7b6ea87e229deb3f24a884dd863d925818b3e0c235394ab079b99a0f23f091e1/angular/angular-cli/issues/4541 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7b6ea87e229deb3f24a884dd863d925818b3e0c235394ab079b99a0f23f091e1/angular/angular-cli/issues/4541 |
| og:image:alt | This is a feature request. I'd like to start discussion around @ngtools/webpack supporting code splitting by third party libs (including ui-router-ng2). Currently the code splitting support in @ngt... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | christopherthielen |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular-cli git https://github.com/angular/angular-cli.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 36891867 |
| octolytics-dimension-repository_nwo | angular/angular-cli |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 36891867 |
| octolytics-dimension-repository_network_root_nwo | angular/angular-cli |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width