I was using vue cli 2 without any custom configuration. Now I upgraded to cli3 and i noticed in the processed HTML it removes ALL whitespace. e.g. if my original html is this:
<div class="link">
<i class="fa fa-lg" :class="item.icon"/>
<span class="hidden-sm hidden-xs">{{item.name}}</span>
</div>
the old (cli 2 + webpack) would convert it into this:
<div class="link"><i class="fa fa-lg fa-calendar"/> <span class="hidden-sm hidden-xs">CALENDAR</span></div>
whereas the new one does this:
<div class="link"><i class="fa fa-lg fa-calendar"/><span class="hidden-sm hidden-xs">CALENDAR</span></div>
note the space is gone before <span class...
which causes this:
to become this:
My vue.config.js is pretty basic:
// vue.config.js
module.exports = {
runtimeCompiler: true
}
I know I can just add
or make other changes to html itself, but the app is quite large and looking for all these places will take days.
Does anybody know the options I need to ensure it optimizes html the same way it did with the old cli+webpack combo?
The simplest way to get started with Vue is to grab the development version script for it and add it to the head tag of your HTML file. Then you can start Vue code inside the HTML file inside of script tags. And have the Vue code connect up with an existing element on your HTML page.
Vue CLI generated projects use public/index. html as a template, which contains the headers and tags you'd like to avoid. The only element there required for Vue is <div id="app"></div> , so you could remove everything but that from public/index. html .
The vue-cli-service serve command starts a dev server (based on webpack-dev-server) that comes with Hot-Module-Replacement (HMR) working out of the box. In addition to the command line flags, you can also configure the dev server using the devServer field in vue.config.js .
The @VamsiKrishna answer works fine, but preserveWhitespace
is deprecated since vue-template-compiler 2.6, you may use new option whitespace
instead:
// vue.config.js
module.exports = {
chainWebpack: config => {
config.module
.rule("vue")
.use("vue-loader")
.loader("vue-loader")
.tap(options => {
// modify the options...
options.compilerOptions.whitespace = 'preserve';
return options;
});
}
};
You may check other options and valid values here.
On Vue 3, You may use application config, here is the docs:
const app = createApp({});
app.config.compilerOptions.whitespace = 'preserve';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With