ngcc with preserveWhitespaces #35871
Comments
|
Indeed you are right that we are not offering this option in ngcc... I think the relevant place is where we create the options for the Angular compiler here: angular/packages/compiler-cli/ngcc/src/packages/entry_point_bundle.ts Lines 51 to 54 in 6b468f9 We need to decide the best approach for supporting this. On the one hand we could just add |
|
Tracking at FW-1972 |
|
@petebacondarwin thanks for response! Is there any workaround I can use now for old libs which use preserveWhitespaces: true while I want to consume them in my Angular 9 app with Ivy enabled? |
|
If you have access to the original library code, could you try specifying it explicitly in the |
|
Yeah, that works. However I do not have source code for every library that I use... |
|
I can't think of any other workaround until we fix the configuration issue. |
|
@tscislo - a quick question... if you turn off Ivy and consume these libraries does the preserve whitespaces option apply to the View Engine built libraries too? I kind of expected ViewEngine libraries to have been built already and so the settings of the consuming app would not affect them. |
|
So here is the thing:
|
|
Hmm, so this is tricky. It really should be the library author's decision on whether whitespace is preserved in their library's templates. Also strange is that in V8 the default is still |
|
@petebacondarwin the option is weirdly named - In Angular 8 (or Angular 9 with View Engine), libraries all use the application's default |
|
OK so ngcc should accept an option to point to a tsconfig.json file (and programmatically to pass the config object directly) so that it will pull in the Angular compiler specific options. |
|
@petebacondarwin well by default ngcc shouldn't change the way the library was compiled either with or without preserveWhitespaces it should know what was set during initial compilation of those libs. It should however be possible to override this by for example honoring consuming project's tsconfig.json file. |
|
As I understand it, in ViewEngine the application actually built the templates for components in libraries; and it used its own configuration to do this. Since ngcc is supposed to make ViewEngine libraries available to Ivy, and it is also compiling the templates, I think the most "compatible" approach is to pass the application configuration through to ngcc. |
|
@petebacondarwin ok so if you're saying that for View Engine Angular compiler in consuming app also builds templates for components in libraries and uses its own config to do that then yes we should pass app configuration through to ngcc for Ivy compilation as well. |
|
That is what @alxhub explained to me :-) |
Previously ngcc never preserved whitespaces but this is at odds with how the ViewEngine compiler works. In ViewEngine, library templates are recompiled with the current application's tsconfig settings, which meant that whitespace preservation could be set in the application tsconfig file. This commit allows ngcc to use the `preserveWhitespaces` setting from tsconfig when compiling library templates. One should be aware that this disallows different projects with different tsconfig settings to share the same node_modules folder, with regard to whitespace preservation. But this is already the case in the current ngcc since this configuration is hard coded right now. Fixes angular#35871
Previously ngcc never preserved whitespaces but this is at odds with how the ViewEngine compiler works. In ViewEngine, library templates are recompiled with the current application's tsconfig settings, which meant that whitespace preservation could be set in the application tsconfig file. This commit allows ngcc to use the `preserveWhitespaces` setting from tsconfig when compiling library templates. One should be aware that this disallows different projects with different tsconfig settings to share the same node_modules folder, with regard to whitespace preservation. But this is already the case in the current ngcc since this configuration is hard coded right now. Fixes angular#35871
Previously ngcc never preserved whitespaces but this is at odds with how the ViewEngine compiler works. In ViewEngine, library templates are recompiled with the current application's tsconfig settings, which meant that whitespace preservation could be set in the application tsconfig file. This commit allows ngcc to use the `preserveWhitespaces` setting from tsconfig when compiling library templates. One should be aware that this disallows different projects with different tsconfig settings to share the same node_modules folder, with regard to whitespace preservation. But this is already the case in the current ngcc since this configuration is hard coded right now. Fixes angular#35871
Previously ngcc never preserved whitespaces but this is at odds with how the ViewEngine compiler works. In ViewEngine, library templates are recompiled with the current application's tsconfig settings, which meant that whitespace preservation could be set in the application tsconfig file. This commit allows ngcc to use the `preserveWhitespaces` setting from tsconfig when compiling library templates. One should be aware that this disallows different projects with different tsconfig settings to share the same node_modules folder, with regard to whitespace preservation. But this is already the case in the current ngcc since this configuration is hard coded right now. Fixes angular#35871
Previously ngcc never preserved whitespaces but this is at odds with how the ViewEngine compiler works. In ViewEngine, library templates are recompiled with the current application's tsconfig settings, which meant that whitespace preservation could be set in the application tsconfig file. This commit allows ngcc to use the `preserveWhitespaces` setting from tsconfig when compiling library templates. One should be aware that this disallows different projects with different tsconfig settings to share the same node_modules folder, with regard to whitespace preservation. But this is already the case in the current ngcc since this configuration is hard coded right now. Fixes angular#35871
Previously ngcc never preserved whitespaces but this is at odds with how the ViewEngine compiler works. In ViewEngine, library templates are recompiled with the current application's tsconfig settings, which meant that whitespace preservation could be set in the application tsconfig file. This commit allows ngcc to use the `preserveWhitespaces` setting from tsconfig when compiling library templates. One should be aware that this disallows different projects with different tsconfig settings to share the same node_modules folder, with regard to whitespace preservation. But this is already the case in the current ngcc since this configuration is hard coded right now. Fixes #35871 PR Close #36189
|
@mhevery @petebacondarwin when (which version) this will be available in angular/compiler-cli? |
|
It is in the 9.1.0-rc.2 release: b08168b |
|
@petebacondarwin any idea when it will be final? |
|
This week, unless we see a serious issue. |
|
This works well as expected. Thanks for your help! @petebacondarwin @mhevery |
|
Great! Thanks for checking in. |
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
I'm using Angular 9 with Ivy to compile my app. This app uses a bunch of libs which it compiles using ngcc form View Engine to Ivy. I want those libs to be compiled by ngcc with preserveWhitespaces: true, currently this does not happen. I tried setting preserveWhitespaces in tsconfig of my project, but it does not work.
When those libs are used as they are without ngcc compilation I get preserveWhitespaces correctly respected.
The text was updated successfully, but these errors were encountered: