Whitespaces on HTML
See original GitHub issueπ Feature request
Command (mark with an x
)
- [x] build
- [x] serve
Description
Hello, weβre experiencing issues when webpack compiles our application because angular does not allow us to modify whitespace settings.
Currently the whitespace settings are not available via the cli config, which causes that each and every single line of HTML code to have a whitespace in between when minified. This settings eventually leads to have HTML code resulting as this:
<a href="#"> My link </a>.
And therefore to have a sentence with spaces around clickable.
The responsible for the HTML and I have tried to find a way to proceed but we havenβt found a consistent solution that solves 100% of the issues, so my question is: Is there any particular reason angular is preventing us to change this setting?
Describe the solution youβd like
Configurable angular-cli or webpack configuration.
Describe alternatives youβve considered
Talking with my team we was considering to expand webpack configuration with ngx-build-plus but we think is a problem to be solved on official cli.
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (6 by maintainers)
Top GitHub Comments
@alxhub @pkozlowski-opensource
My coworker and I have been revisiting the issue carefully, taking your examples in consideration and trying to get deeper in what the problemβs root could be. And this is what we came out with.
If we take this example:
And we make the compiler to trim the spaces, we would have the following output:
Which, of course, is not desirable because the we have intendedly typed a space character that the compiler is removing afterwards.
But nobody asked here for the compiler to trim spaces.
Yet, funnily enough, if we type the following:
That space is being trimmed by the compiler, and it doesnβt matter if we wrap it within a <p> element:
The only way to prevent the compiler from trimming that space is to add more text or a
But adding is not always a way to go, as it conditions responsiveness, not to mention that adding text is often not even a possibility.
We have also realized that the current compiler obeys the following rules:
After deeply (hopefully) explaning what the problem is, I would like to invite you reopening this issue and consider the following rules instead:
Acknowledgement:
The rules just exposed have some problems as for example:
No breaking line character means no output spaces when compiling indented markup:
The following block:
Would output no spaces whatsoever between both <a>. This could be easily addressed by manually add a space after closing the first <a>.
Given the scenario in which you can manually add a space youβre missing and the scenario in which thereβs no way to get rid of spaces being generated for keeping a somewhat-readable structure on HTML, I find way more intuitive and reasonable to βforceβ users to type the spaces they want to output rather to assume on their behalf where do they want or not spaces to be printed and βforceβ them to have a cryptically-indented nightmarish HTML markup that is already sweetened (read: complexed) with variables, loops, directives, bindings, etc.
Differentiate between intendedly typed spaces and indentation spaces:
Since indentations can be made up of space characters, a blind rule for deleting/keeping space characters is not suitable. The rule should be a bit more picky analizing wether there is a breaking line character before the space or if there is text/HTML markup around the space in order to accurately decide what do those spaces mean and what to do with them.
@segux https://github.com/angular/angular-cli/issues/10859#issuecomment-390808375