Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perserveWhitespace: false #1020

Closed
embersdev opened this issue Mar 21, 2018 · 13 comments
Closed

perserveWhitespace: false #1020

embersdev opened this issue Mar 21, 2018 · 13 comments

Comments

@embersdev
Copy link

Version

3.0.0-beta.6

Reproduction link

1864cef

Steps to reproduce

1864cef

What is expected?

preserveWhitespace: true

What is actually happening?

preserveWhitespace: false


White space is an expected design pattern in HTML. I would expect the default to be true and the few people that want false to have to configure it. This will be a challenge for anyone new to vue/webpack in that they wont understand why their formatting doesn't look normal.

@yyx990803
Copy link
Member

This is an intended change. If you don't want it, you can configure it by tapping vue-loader's option in vue.config.js. See docs for more details.

@embersdev
Copy link
Author

I have changed it.

My only concern is that i personally consider false as an advanced feature you wouldn't normally want which in turn means any new developers to Vue will stumble on this. This version of the CLI is pretty awesome with the zero config but i would expect the defaults to be what a new/entry/mid-level developer would expect and then people that actually know what this setting is for can change it with a config.

Just an opinion and figured i would express it.

@yyx990803
Copy link
Member

That's true, I guess this is a tradeoff since having preserveWhitespace: false does result in smaller bundles and slightly better perf in theory, and that's also something we want to have by default.

Maybe we should expose this as a top level option to make it easier to tweak.

@yyx990803 yyx990803 reopened this Mar 21, 2018
@Justineo
Copy link
Member

Maybe we should provide a enum option for this:

whitespace: strip | collapse | preserve

Setting to collapse may give us smaller bundle size while be consistent to HTML's default behavior in most cases (except for those with white-space: pre in style).

@yyx990803
Copy link
Member

This would be pending vuejs/vue#7598

@bruceCzK
Copy link

In case of someone doesn't know how to change the option back, just put the following code in vue.config.js

chainWebpack: config => {
    config.module
      .rule('vue')
      .use('vue-loader')
      .loader('vue-loader')
      .tap(options => {
        options.compilerOptions.preserveWhitespace = true
        return options
      })
  }

@viaregio
Copy link

@bruceCzK Thank you very much

I have two button elements separated by a space by intention. After upgrading my project to version 3 of the CLI the space is gone.
If preserveWhitespace == false is the new default then it should have not such side effects. No browser I know removes all whitespaces, they collapse multiple whitespaces into one. This should be the default behaviour. This is just my opinion but maybe it is something to consider.

@Justineo
Copy link
Member

F.Y.I. to all: We'll have new strategy available in the upcoming v2.6. See vuejs/vue#9208 (comment).

@sodatea sodatea mentioned this issue Mar 16, 2019
19 tasks
sodatea added a commit that referenced this issue Apr 22, 2019
BREAKING CHANGE:
Detailed explanation: vuejs/vue#9208 (comment)

Take the following template as example:
```
<p>
  Welcome to <b>Vue.js</b> <i>world</i>.
  Have fun!
</p>
```

With `preserveWhitespace: false`, it was compiled as:
```
<p> Welcome to <b>Vue.js</b><i>world</i>. Have fun! </p>
```

With `whitespace: 'condense'`, it is now compiled as:
```
<p> Welcome to <b>Vue.js</b> <i>world</i>. Have fun! </p>
```

Note the **inline whitespace between tags** is preserved.

Closes #1020
@Alik2015
Copy link

Alik2015 commented May 8, 2019

Just o add to this have the latest cli and preserveWhitespace = true still does not work my index.html in public folder is well spaced and laid out but when npm run build the index.html in dist folder has whitespace removed.

@zires
Copy link

zires commented Jul 8, 2019

In case of someone doesn't know how to change the option back, just put the following code in vue.config.js

chainWebpack: config => {
    config.module
      .rule('vue')
      .use('vue-loader')
      .loader('vue-loader')
      .tap(options => {
        options.compilerOptions.preserveWhitespace = true
        return options
      })
  }

Thank u!!! You save my time!!

@andreasvirkus
Copy link

For people seeing this with vue-cli 3.*, there's a working solution here: vuejs/vue#10485 (comment)

// vue.config.js
module.exports = {
  chainWebpack: config => {
    config.module
      .rule('vue')
        .use('vue-loader')
          .tap(args => {
            args.compilerOptions.whitespace = 'preserve'
          })
  }
}

@sudoris
Copy link

sudoris commented Mar 5, 2020

For people seeing this with vue-cli 3.*, there's a working solution here: vuejs/vue#10485 (comment)

// vue.config.js
module.exports = {
  chainWebpack: config => {
    config.module
      .rule('vue')
        .use('vue-loader')
          .tap(args => {
            args.compilerOptions.whitespace = 'preserve'
          })
  }
}

Thanks, this is what works for vue cli 3 and 4 atm. Should put this in the official docs imo.

@antoniandre
Copy link

For people seeing this with vue-cli 3.*, there's a working solution here: vuejs/vue#10485 (comment)

// vue.config.js
module.exports = {
  chainWebpack: config => {
    config.module
      .rule('vue')
        .use('vue-loader')
          .tap(args => {
            args.compilerOptions.whitespace = 'preserve'
          })
  }
}

This doesn't seem to work anymore with Vue 3, it throws the error: "TypeError: Cannot set property 'whitespace' of undefined". Any workaround for Vue 3?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants