diff options
| author | rr- <rr-@sakuya.pl> | 2016-04-13 18:58:34 +0200 |
|---|---|---|
| committer | rr- <rr-@sakuya.pl> | 2016-04-13 18:58:34 +0200 |
| commit | 5796b07908d99edd9224486a48969316779d379b (patch) | |
| tree | 39babe6e32990c8757fbaa674112bf2a0cc4d029 /client/build.js | |
| parent | 4df05fe3ecb8c2adb3e70b3c8ed78468b1120af7 (diff) | |
client/build: don't keep templates in DOM
Diffstat (limited to 'client/build.js')
| -rw-r--r-- | client/build.js | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/client/build.js b/client/build.js index 80a7cf3..81fc189 100644 --- a/client/build.js +++ b/client/build.js @@ -58,28 +58,33 @@ function getConfig() { function bundleHtml(config) { const minify = require('html-minifier').minify; const baseHtml = fs.readFileSync('./html/index.htm', 'utf-8'); + const minifyOptions = { + removeComments: true, + collapseWhitespace: true, + conservativeCollapse: true, + }; glob('./html/**/*.hbs', {}, (er, files) => { - let templatesHtml = ''; + let templates = {}; for (const file of files) { - templatesHtml += util.format( - '<template id=\'%s-template\'>%s</template>', - path.basename(file, '.hbs').replace(/_/g, '-'), - fs.readFileSync(file)); + const name = path.basename(file, '.hbs').replace(/_/g, '-'); + templates[name] = minify( + fs.readFileSync(file, 'utf-8'), minifyOptions); } + const templatesHolder = util.format( + '<script type=\'text/javascript\'>' + + 'const templates = %s;' + + '</script>', + JSON.stringify(templates)); + const finalHtml = baseHtml - .replace(/(<\/head>)/, templatesHtml + '$1') + .replace(/(<\/head>)/, templatesHolder + '$1') .replace( /(<title>)(.*)(<\/title>)/, util.format('$1%s$3', config.name)); fs.writeFileSync( - './public/index.htm', - minify( - finalHtml, { - removeComments: true, - collapseWhitespace: true, - conservativeCollapse: true})); + './public/index.htm', minify(finalHtml, minifyOptions)); console.info('Bundled HTML'); }); } |