Vue-cli: `vue.config.js` vueLoader.preserveWhitespace = false not work

Created on 8 Mar 2018  ·  12Comments  ·  Source: vuejs/vue-cli

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 未生效

Most helpful comment

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

All 12 comments

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

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

@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.

@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);
  },
};

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

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

@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

@yyx990803 @LinusBorg
could u please give a solution?

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.

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

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

@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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

miyamoto-san picture miyamoto-san  ·  3Comments

eladcandroid picture eladcandroid  ·  3Comments

DrSensor picture DrSensor  ·  3Comments

JIANGYUJING1995 picture JIANGYUJING1995  ·  3Comments

sanderswang picture sanderswang  ·  3Comments