-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhandlebars-min.js
34 lines (26 loc) · 1.1 KB
/
handlebars-min.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
29
30
31
32
33
34
//handlebars template minifier - minifies templates before they're compiled to
// reduce output file size by a tiny amount.
// known not to work for <pre> tags (as in, it disregards the pre)
//and for quoted text (as in, it disregards the quotes.)
var min = function(input){
"use strict";
return input
//get rid of duplicate whitespace
.replace(/[\s][\s]*/gi, " ")
//remove whitespace before the ">" of a tag
.replace(/[\s]*>/gi, ">")
//remove whitespace after the start of a tag
.replace(/>[\s]*/gi, ">")
//remove whitespace before the close of a tag
.replace(/[\s]*</gi, "<")
//the previous removal may have turned {{> partial}} into {{>partial}}
// that's bad. undo it.
.replace(/{{2}>/gi, "{{> ")
//the previous removal may have turned {{!< layout}} into {{!<layout}}
// that's bad. undo it.
// https://github.com/barc/express-hbs
.replace(/{{2}!</gi, "{{!< ")
//remove whitespace after the "<" of a tag
.replace(/<[\s]/gi, "<");
};
exports = module.exports = min;