Take a look at vueify.
Minification is automatically applied on template, when compiled with NODE_ENV=production.
You won't need to place your html in separate file in that case, as well.
But you could if needed: just omit <template>
block and add template to module.exports object as usual:
<script>
module.exports = {
template: require('./template1.html'),
};
</script>
Research
So, in fact its minification is purely decorational.
As follows from dependencies list, vueify depends on html-minifier.
Let's take a look at code:
// production minifiers
if (process.env.NODE_ENV === 'production') {
var htmlMinifier = require('html-minifier')
// required for Vue 1.0 shorthand syntax
var htmlMinifyOptions = {
customAttrSurround: [[/@/, new RegExp('')], [/:/, new RegExp('')]]
}
}
The only option here is customAttrSurround
, thus, anything else will be taken from default values.
Result
We have several options here:
- Fix the source once. Just add your config here.
- Create an issue on github. Minifier config surely must be included in vue.config.js.
- Pull request.
Final solution by asker
The code above should be replaced by this:
// production minifiers
if (process.env.NODE_ENV === 'production') {
var htmlMinifier = require('html-minifier')
// required for Vue 1.0 shorthand syntax
var htmlMinifyOptions = {
customAttrSurround: [[/@/, new RegExp('')], [/:/, new RegExp('')]],
collapseWhitespace: true,
removeComments: true
}
}
See my pull request