You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some interface that would rebuild library project that is generated with ng g library niceLib.
Of Course the best option would be ng serve niceLib or include it to the application serve. Or at least another build that allow to add --watch parameter like it does for for application. Here what I mean:
for application we are allowed to run ng build --watch
for library we have ng build niceLib
but we can't use ng build niceLib --watch, as it throws Unknown option: '--watch'
The new angular.json specifies a 'defaultProject' of which you generate and then are able to use the generate library command which creates the subsequent projects/ and updates the angular.json.
What I'm doing is using my 'defaultProject' as the demo app and then import { ProjectModule} from 'projects/name/src/public_api'.
When serving the app, any file changes inside 'defaultProject' or libraries projects/ reloads the development server.
Reacted by Giovanni Bassi, Roman Niklaus, Schmack, Tom, Matthias Meyer and zshn
In the future we want to add watch support to building libraries so it is faster to see changes.
We are also planning to add internal dependency support to Angular CLI. This means that Angular CLI would know your app depends on your library, and automatically rebuilds the library when the app needs it.
Reacted by Danny Blue, Nodarii, Ro Brett, Eduard Lepner, Kyoz, Yaroslav Admin, Brecht Carlier, Sanoj Antony, evyatarrosner, Sanoj Antony and 4 more
The proposal from @Tyler-V is by far the only acceptable at this moment. No developer can take the productivity hit that manually rebuilding the library causes. Even with an automated watcher the build time increases substantially. Until there is a fix I, differently from what the ng team proposes, will err on the side of productivity instead of caution.
@filipesilva and @alan-agius4 worked on some changes this morning and I'm currently able to serve my library from my demo project as suggested and build all in --aot!
BTW, to anyone interested, it is easier to, instead of using import { ProjectModule } from 'projects/lib/src/public_api' to simply change tsconfig.json to "lib": ["projects/lib/src/public_api"].
When there is an acceptable fix simply change this one line back to "lib": ["dist/lib"].
Reacted by Adrien Crivelli, Brecht Carlier, Ika Pkhakadze, Markus Thiel, Vincenzo Farruggia, schaveyt, sr480 and jkubiszewski
I've been using the ng build my-lib --watch for some time now but I 've been unhappy with the rebuild time.
Today I changed the default path mapping in main project's tsconfig to point to lib's public_api:
now the libraries are built by ng serve command, changes propagates super fast and also the Chrome devtools are able to debug raw typescript files.
Sounds too good to be true but really works.
Reacted by Sauruz, Gaétan Collaud, Diego Bonura, Tracy Lee, gms1, Mohammad Hossein Amri, Maxzilla, gentoo90, Nick Partridge, Alberto Chiesa and 13 more
Reacted by Thomas Rijsewijk
Reacted by Stefan Paul Noack, Gaétan Collaud, Rubén Fraile, Vimalan Sakthivel, Mohammad Hossein Amri, Nick Partridge, Maksim Popov, tnicola, Sergiu Bologa, Daniel and 6 more
Reacted by tnicola, David Moorhead, Sergiu Bologa, Daniel, Maxime, Dennis Zoma, jkubiszewski and Daniel Sig
@filipesilva how would you handle project with multiple library dependencies?
For example project A depends on lib-B and lib-C and lib-C depends on lib-D, if changes are made to lib-D, will building project A only compile lib-C and lib-D?
Heya, this feature request is something we are aware of and talk about in https://github.com/angular/angular-cli/wiki/stories-create-library#why-do-i-need-to-build-the-library-everytime-i-make-changes.
@playground the CLI at the moment does not rebuild project dependencies at all. You have to manually build those libraries in separate processes, and you probably want to keep them in watch mode so the libraries are rebuilt.
On my machine rebuilding the library in a separate process triggers the rebuild of the main app too early and the resulting library code in the app is always one change behind. The solution by @GeorgeKnap works, though.
Wow...so that really does work eerily well...do you know what the downsides are of using the projects path instead of dist? Surely there must be some reasons NOT to do that or else angular would have it be the default / recommended path?
@rdhelms
The point is you are pointing to the library source, not the library output folder. That way ng serve works with source typescript files.
However I think this is good only for development. For prod environment I have the libraries built separately in npm feed and using them as any other 3rd party dependency.
I came back to this, as it has been a while since I tried the whole "double watch" solution, and it could have improved on ng7.
Not at all. It is still much slower than running everything as a single project.
I have just updated my whole project and deps to version 7 and I can say it is better than before, but still to slow.
I hope a solution eventually comes up, until then I will keep using the tsconfig path remap.
Reacted by Brainy Devs, Nodarii, schaveyt and Rémy Binsztock
@GeorgeKnap I guess your solution stopped working on Angular 8.2.0-next.0 (Ivy enabled) 😐
I'm getting an error:
ERROR in ENOENT: no such file or directory, scandir '/[...]/projects/lib/src/public_api'
This can of course be just a bug on the Angular-side but I couldn't find any according issue.
Update: I fixed it by changing the paths definition in tsconfig.json to "lib/*": [ "projects/lib/src/*" ] and changing all imports to import ... from 'lib/public_api'.
angular-automatic-lock-bot commented on Sep 9, 2019
Activity
Tyler-V commentedon May 4, 2018
The new
angular.jsonspecifies a'defaultProject'of which you generate and then are able to use the generate library command which creates the subsequentprojects/and updates theangular.json.What I'm doing is using my
'defaultProject'as the demo app and thenimport { ProjectModule} from 'projects/name/src/public_api'.When serving the app, any file changes inside
'defaultProject'or librariesprojects/reloads the development server.filipesilva commentedon May 4, 2018
Heya, this feature request is something we are aware of and talk about in https://github.com/angular/angular-cli/wiki/stories-create-library#why-do-i-need-to-build-the-library-everytime-i-make-changes.
beeman commentedon May 4, 2018
As a workaround you can use
nodemonto rebuild the libraries:It's on the slow side but does get the job done. One downside is that you need to run a separate process for each of the libs you want to rebuild.
hwangzhiming commentedon May 7, 2018
try
File Watchersif you useWebStorm.giggio commentedon May 11, 2018
The proposal from @Tyler-V is by far the only acceptable at this moment. No developer can take the productivity hit that manually rebuilding the library causes. Even with an automated watcher the build time increases substantially. Until there is a fix I, differently from what the ng team proposes, will err on the side of productivity instead of caution.
Tyler-V commentedon May 11, 2018
@giggio,
@filipesilva and @alan-agius4 worked on some changes this morning and I'm currently able to serve my library from my demo project as suggested and build all in --aot!
You can view the changes here, specifically the PR by filipesilva https://github.com/Tyler-V/ngx-easy
I believe changes were committed and merged on ng-packagr to support this.
https://github.com/dherges/ng-packagr/pull/862
giggio commentedon May 11, 2018
BTW, to anyone interested, it is easier to, instead of using
import { ProjectModule } from 'projects/lib/src/public_api'to simply change tsconfig.json to"lib": ["projects/lib/src/public_api"].When there is an acceptable fix simply change this one line back to
"lib": ["dist/lib"].giggio commentedon May 11, 2018
@Tyler-V That is awesome, but with what dependency and tools versions?
Tyler-V commentedon May 11, 2018
@giggio
I'm using all @latest packages with the proper scoped lib configurations as suggested by @filipesilva
You can use my project as a reference on how I am serving my demo to develop the libraries with refresh.
kyoz commentedon May 24, 2018
@giggio I also use that way 🐱. With projects do have UI. It's really paintful to rebuild library and re-run everytime we do have a change 😢
Enable rebuild of demo when lib changes
Enable rebuild of demo when lib changes
8 remaining items
GeorgeKnap commentedon Sep 24, 2018
I've been using the
ng build my-lib --watchfor some time now but I 've been unhappy with the rebuild time.Today I changed the default path mapping in main project's tsconfig to point to lib's public_api:
now the libraries are built by
ng servecommand, changes propagates super fast and also the Chrome devtools are able to debug raw typescript files.Sounds too good to be true but really works.
kroeder commentedon Sep 24, 2018
@alan-agius4 we have a repo with 6 angular projects inside. Are there already plans on solving
A depends on Bwhile watching all projects?If I watch
AbutBwasn't compiled yet,Afails. Do I have to manually know the dependencies of each library and start watch mode one after another?Something like
ng watch --all-projectswould be super cool in my naive thinking process 😄playground commentedon Oct 8, 2018
@filipesilva how would you handle project with multiple library dependencies?
For example project A depends on lib-B and lib-C and lib-C depends on lib-D, if changes are made to lib-D, will building project A only compile lib-C and lib-D?
filipesilva commentedon Oct 9, 2018
@playground the CLI at the moment does not rebuild project dependencies at all. You have to manually build those libraries in separate processes, and you probably want to keep them in watch mode so the libraries are rebuilt.
Noah1989 commentedon Nov 9, 2018
On my machine rebuilding the library in a separate process triggers the rebuild of the main app too early and the resulting library code in the app is always one change behind. The solution by @GeorgeKnap works, though.
vimalans commentedon Dec 10, 2018
@GeorgeKnap 's suggestion works!
nickofthyme commentedon Jan 9, 2019
@GeorgeKnap you're a lifesaver! Thanks 🎉
rdhelms commentedon Jan 10, 2019
@GeorgeKnap
Wow...so that really does work eerily well...do you know what the downsides are of using the
projectspath instead ofdist? Surely there must be some reasons NOT to do that or else angular would have it be the default / recommended path?GeorgeKnap commentedon Jan 10, 2019
@rdhelms
The point is you are pointing to the library source, not the library output folder. That way
ng serveworks with source typescript files.However I think this is good only for development. For prod environment I have the libraries built separately in npm feed and using them as any other 3rd party dependency.
Does it answer your question?
giggio commentedon Feb 19, 2019
I came back to this, as it has been a while since I tried the whole "double watch" solution, and it could have improved on ng7.
Not at all. It is still much slower than running everything as a single project.
I have just updated my whole project and deps to version 7 and I can say it is better than before, but still to slow.
I hope a solution eventually comes up, until then I will keep using the tsconfig path remap.
dmichael266 commentedon Apr 26, 2019
@GeorgeKnap you just saved me a few hours a day probably! Can't thank you enough.
wottpal commentedon Jul 3, 2019
@GeorgeKnap I guess your solution stopped working on Angular 8.2.0-next.0 (Ivy enabled) 😐
I'm getting an error:
This can of course be just a bug on the Angular-side but I couldn't find any according issue.
Update: I fixed it by changing the
pathsdefinition intsconfig.jsonto"lib/*": [ "projects/lib/src/*" ]and changing all imports toimport ... from 'lib/public_api'.angular-automatic-lock-bot commentedon Sep 9, 2019
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.
feat(@angular-devkit/build-ng-packagr): add support for `watch` when …