Skip to content
This repository was archived by the owner on Dec 26, 2018. It is now read-only.

Commit 95954c0

Browse files
committed
Disable html-minifier removeRedundantAttributes flag by default
This avoid removing the "type" attribute on <input type="text"> as some CSS selectors may depend on the type attribute. Fixes #45. Also added the `htmlMinifier` field in config that allows the user to configure the behavior of the minifier.
1 parent 1761d2c commit 95954c0

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

lib/compiler.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var compilers = require('./compilers')
99
var options = require('./compilers/options')
1010
var rewriteStyle = require('./style-rewriter')
1111
var rewriteTemplate = require('./template-rewriter')
12+
var assign = require('object-assign')
1213
var Emitter = require('events').EventEmitter
1314

1415
// production minifiers
@@ -21,7 +22,9 @@ if (process.env.NODE_ENV === 'production') {
2122
removeComments: true,
2223
collapseBooleanAttributes: true,
2324
removeAttributeQuotes: true,
24-
removeRedundantAttributes: true,
25+
// this is disabled by default to avoid removing
26+
// "type" on <input type="text">
27+
removeRedundantAttributes: false,
2528
useShortDoctype: true,
2629
removeEmptyAttributes: true,
2730
removeOptionalTags: true
@@ -45,7 +48,9 @@ compiler.loadConfig = function () {
4548
compiler.applyConfig = function (config) {
4649
// copy user options to default options
4750
Object.keys(config).forEach(function (key) {
48-
if (key !== 'customCompilers') {
51+
if (key === 'htmlMinifier') {
52+
htmlMinifyOptions = assign(htmlMinifyOptions, config[key])
53+
} else if (key !== 'customCompilers') {
4954
options[key] = config[key]
5055
} else {
5156
// register compilers

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"cssnano": "^3.3.2",
2626
"es6-promise": "^3.0.2",
2727
"hash-sum": "^1.0.2",
28-
"html-minifier": "^0.8.0",
28+
"html-minifier": "^1.0.0",
2929
"lru-cache": "^2.7.0",
3030
"object-assign": "^4.0.1",
3131
"parse5": "^1.5.0",

test/expects/basic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ exports.default = {
3737
}
3838
};
3939
if (module.exports.__esModule) module.exports = module.exports.default
40-
;(typeof module.exports === "function"? module.exports.options: module.exports).template = "<h1 :id=id @click=hi>hello</h1>"
40+
;(typeof module.exports === "function"? module.exports.options: module.exports).template = "<h1 :id=id @click=hi>hello</h1><input type=text>"

test/fixtures/basic.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
<template>
88
<h1 :id="id" @click="hi">hello</h1>
9+
<input type="text">
910
</template>
1011

1112
<script>

0 commit comments

Comments
 (0)