summaryrefslogtreecommitdiff
path: root/client/build.js
diff options
context:
space:
mode:
authorrr- <rr-@sakuya.pl>2016-07-30 23:05:46 +0200
committerrr- <rr-@sakuya.pl>2016-07-30 23:12:32 +0200
commite29136970166496a2a0518910dba4dab6241a9bf (patch)
tree87fca46fecff28a1fcf4946dcf2e107d7cabf6a9 /client/build.js
parent6e3462187d6a54e242e45aee8b9083634a839d69 (diff)
client/build: fix minifying adding ghost spaces
HTML minifier added ghost spaces around some of <%- %> even despite <!-- --> trick.
Diffstat (limited to 'client/build.js')
-rw-r--r--client/build.js15
1 files changed, 14 insertions, 1 deletions
diff --git a/client/build.js b/client/build.js
index 5b84d21..0227309 100644
--- a/client/build.js
+++ b/client/build.js
@@ -99,7 +99,20 @@ function bundleHtml(config) {
compiledTemplateJs += 'let templates = {};';
for (const file of files) {
const name = path.basename(file, '.tpl').replace(/_/g, '-');
- const templateText = minifyHtml(readTextFile(file, 'utf-8'));
+ const placeholders = [];
+ let templateText = readTextFile(file, 'utf-8');
+ templateText = templateText.replace(
+ /<%.*?%>/ig,
+ (match) => {
+ const ret = '%%%TEMPLATE' + placeholders.length;
+ placeholders.push(match);
+ return ret;
+ });
+ templateText = minifyHtml(templateText);
+ templateText = templateText.replace(
+ /%%%TEMPLATE(\d+)/g,
+ (match, number) => { return placeholders[number]; });
+
const functionText = underscore.template(
templateText, {variable: 'ctx'}).source;
compiledTemplateJs += `templates['${name}'] = ${functionText};`;