question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: provide option for removing all spaces arround tag

See original GitHub issue

What problem does this feature solve?

For now, spaces around text tag will be kept at least one space: https://github.com/vuejs/vue/tree/dev/packages/vue-template-compiler#options

<!-- source -->
<div>
  <span>
    foo
  </span>   <span>bar</span>
</div>

<!-- whitespace: 'preserve' -->
<div> <span>
  foo
  </span> <span>bar</span> </div>

<!-- whitespace: 'condense' -->
<div><span> foo </span> <span>bar</span></div>

Sometimes, it will keep some space we don’t want:

<!-- source -->
<span>
  一段很长的文字………………,
<span>

<!-- become -->
<span> xx </span>

<!-- if we write source like this -->
<span>a_long_long_chinese_characters…<span>

<!-- it will be formatted by prettier or etc like this, very bad -->
<span
  >a_long_long_chinese_characters…</span
>

Our code standard always: build tool (webpack) will kill all spaces around tag. If we need a real space, use &nbsp; like this:

<!-- source if no need for spaces -->
<span>
    <i class="icon"></i>
    文本
</span>
<!-- result -->
<span><i class="icon"></i>文本</span>

<!-- source if need for spaces -->
<span>
    &nbsp;
    <i class="icon"></i>
    &nbsp;文本&nbsp;
</span>
<!-- result -->
<span>&nbsp;<i class="icon"></i>&nbsp;文本&nbsp;</span>

In this way, we get a great experience with react and vue@1.x (compress html myself).

now we are using SFC, vue-loader haven’t provide this option. Spaces around tag will be kept at least one space. So we hope vue-loader can provide an option to remove these spaces.

What does the proposed API look like?

compilerOptions: {
  whitespace: 'collapse'
}

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:14
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
masquevilcommented, Aug 28, 2019

I can list more example, but it is not what I’m requesting. JSX has this feature, And I think there should be an ability for developer to choose which code style they prefer, rather than no choice.

eg1: Which one do you think is the best? We choose 3.

<!-- source code 1 -->
<p attr1="1" attr2="1" attr3="1" attr4="1" attr5="1" attr6="1" attr7="1" attr8="1">a_long_long_chinese_sentence………………………………</p>

<!-- source code 2 -->
<p
  attr1="1"
  attr2="1"
  attr3="1"
  attr4="1"
  attr5="1"
  attr6="1"
  attr7="1"
  attr8="1"
>a_long_long_chinese_sentence………………………………</p>

<!-- source code 3 -->
<p
  attr1="1"
  attr2="1"
  attr3="1"
  attr4="1"
  attr5="1"
  attr6="1"
  attr7="1"
  attr8="1"
>
  a_long_long_chinese_sentence………………………………
</p>

eg2: Which one do you think is better? We choose 1.

<!-- source code 1 -->
<router-link
  v-if="someCondition"
  class="link-type-a"
  to="an-long-long-url"
>
  <icon type="some-icon" />
  <span class="highlight-link">text</span>
</router-link>
<router-link
  v-else
  class="link-type-b"
  to="an-long-long-url"
>
  text
</router-link>

<!-- source code 2 -->
<router-link
  v-if="someCondition"
  class="link-type-a"
  to="an-long-long-url"
>
  <icon type="some-icon" />
  <span class="highlight-link">text</span>
</router-link>
<router-link
  v-else
  class="link-type-b"
  to="an-long-long-url"
>text</router-link>
1reaction
Justineocommented, Aug 27, 2019

As I understand the feature you are asking for is exactly the same with the original proposal here in #9208. Maybe we can add a new value for the whitespace option value like 'jsx'? @yyx990803

Read more comments on GitHub >

github_iconTop Results From Across the Web

Option to trim whitespace between tags · Issue #3080 ...
I'm used to JSX, where whitespace is automatically trimmed, and you have to insert it manually with {" "} when you want it....
Read more >
Feature Requests
I would like to have a native integration with WPAdverts that allows Spaces to publish classifieds via their Spaces profile. The classifieds should...
Read more >
How to auto-remove trailing whitespace in Eclipse?
In order to do that right-click on your project and go to Properties -> Java Editor -> Save Actions. From there you can...
Read more >
About Twitter Spaces
Listeners can request permission to speak from the host by selecting the Request icon below the microphone. Step 6. When creating a Space,...
Read more >
Working with ticket tags
Deleting a tag from a ticket only removes the tag from that ticket; the tag will still appear on other tickets and in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found