-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
28 lines (27 loc) · 779 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"use strict";
const htmlMinifier = require('html-minifier');
module.exports = function({ types: t }, options) {
options = Object.assign({
separator: 'babel-polymer-minify-html:mockup',
tagNames: ['html'],
htmlMinifier: {
removeComments: true,
collapseWhitespace: true,
minifyCSS: true,
},
}, options);
return {
visitor: {
TaggedTemplateExpression: function(path, state){
if (options.tagNames.indexOf(path.node.tag.name) >= 0) {
const oldValue = path.node.quasi.quasis.map(x=>x.value.cooked).join(options.separator);
const newValue = htmlMinifier.minify(oldValue, options.htmlMinifier);
path.node.quasi.quasis = newValue.split(options.separator).map(x=>t.templateElement({
cooked: x,
raw: x,
}));
}
},
}
}
}