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

vue.config.js vueLoader.preserveWhitespace = false not work #962

Closed
yozman opened this issue Mar 8, 2018 · 12 comments
Closed

vue.config.js vueLoader.preserveWhitespace = false not work #962

yozman opened this issue Mar 8, 2018 · 12 comments

Comments

@yozman
Copy link
Contributor

yozman commented Mar 8, 2018

Version

3.0.0-beta.6

Reproduction link

https://jsfiddle.net/yozman/3Lcwjrts/

Steps to reproduce

vue.config.js

What is expected?

$slots.default 去掉空格

What is actually happening?

$slots.default 空格一直存在


感觉是 vueLoader 的 preserveWhitespace 未生效

@jkzing
Copy link
Member

jkzing commented Mar 9, 2018

Tested, and it's working with or without vue.config.js.🤔

@yozman
Copy link
Contributor Author

yozman commented Mar 9, 2018

@jkzing
r u sure?
$slots.default.length 一直是包含空格的

@jkzing
Copy link
Member

jkzing commented Mar 9, 2018

@yozman Yes, from what I'm seeing, preserveWhitespace is working as expected.
Maybe you could provide your problematic code (like a github repo) to help reproduce the issue.

@yozman
Copy link
Contributor Author

yozman commented Mar 9, 2018

@jkzing
I use .js without .vue

// parent.js
import Child from './child';

const template = /*html*/`
  <child>
    <h1>one</h1>
    <h1>two</h1>
  </child>
`;

export default {
  template,
  components: {
    Child,
  },
};

// child.js
const template = /*html*/`
  <div>
    <slot/>
  </div>
`;

export default {
  template,

  created() {
    console.log(this.$slots.default.length);
  },
};

@LinusBorg
Copy link
Member

Well, if you use js files, then you are not using vue-loader, which only takes care of .vue files.

@yyx990803
Copy link
Member

Inline JS strings are compiled by the runtime compiler, not vue-loader.

@yozman
Copy link
Contributor Author

yozman commented Mar 10, 2018

@yyx990803 @LinusBorg
how can I set preserveWhitespace to runtime compiler?
is there any way except directly

// ...

export default {
  render: () => Vue.compile(template, {
    preserveWhitespace: false,
  }),
};

maybe there should be a way to set preserveWhitespace like Vue.config

@yozman
Copy link
Contributor Author

yozman commented Mar 11, 2018

@yyx990803 @LinusBorg
could u please give a solution?

@LinusBorg
Copy link
Member

LinusBorg commented Mar 11, 2018

This would have to be addressed in the vue repository, not here.

Toy should open a feature request over there and explain the use case.

@yyx990803
Copy link
Member

@yozman you cannot. If you want that behavior you have to use pre-compile via vue-loader.

@yozman
Copy link
Contributor Author

yozman commented Mar 12, 2018

@yyx990803 why don't u make a feature to that, as every FE known everything is js, not .vue

@sunchanglong
Copy link

sunchanglong commented Mar 7, 2019

@yyx990803 why don't u make a feature to that, as every FE known everything is js, not .vue

yes, inline template need preserve whitespace between tags. @yyx990803
https://codepen.io/sunchanglong/pen/YgpmKV?editors=1111
image

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

No branches or pull requests

5 participants