ktsn / vue-template-loader

Vue.js 2.0 template loader for webpack
MIT License
266 stars 26 forks source link

Expose preserveWhitespace to vue-template-loader #44

Closed kennardconsulting closed 6 years ago

kennardconsulting commented 6 years ago

Thanks for all your hard work on vue-template-loader!

Would it be possible to expose the preserveWhitespace option as discussed here: https://github.com/vuejs/vue/issues/3934

At present my input looks like this:

<p>
    My gross annual salary is
</p>

And my output looks like this:

_c('p',[_vm._v("\r\n\t\tMy gross annual salary is\r\n\t\t")

I would love it to look like this:

_c('p',[_vm._v("My gross annual salary is")

ktsn commented 6 years ago

We can't add the feature which vue-template-compiler does not support.

kennardconsulting commented 6 years ago

Sorry for not being clear. I believe preserveWhitespace is already supported by vue-template-compiler. As explained here:

https://github.com/vuejs/vue/blob/d362d64633f00f8cbf1613c424d8852fb45c7596/packages/vue-template-compiler/README.md#options

I think I just need you to expose it?

ktsn commented 6 years ago

We can expose the option, but preserveWhitespace: false does not trim text nodes but eliminate whitespace between elements. https://jsfiddle.net/m5zyuvux/

kennardconsulting commented 6 years ago

Thanks for being so responsive!

I take your point. I understand now that this won't solve my problem. It may be useful to expose it for now anyway, and hopefully expose some other option in the future (preserveWhitespaceWithinElements or something).

It's actually a correctness issue, I think.

kennardconsulting commented 6 years ago

Investigating this some more, I've realized that - for my use case - it would be sufficient to chain the loader with something that can strip the whitespace. However (possibly because of the inline/normal/post loader thing) I don't seem to be able to do this:

        test: /\.html$/,
        use: [ {
            loader: 'html-loader',
            options: {
                minimize: true
            }
        }, 'vue-template-loader' ]

The vue-template-loader ignores the html-loader. Is there a way to make this work?