generated from mhkeller/layercake-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre-render.js
28 lines (20 loc) · 926 Bytes
/
pre-render.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
require('svelte/register');
const fs = require('fs');
const path = require('path');
const CleanCSS = require('clean-css');
const { minify } = require("html-minifier");
const config = require('./config.json');
const includeJS = config.hydrate;
const App = require('./build/App.js');
const templatePath = './src/template.svelte';
const outDir = 'public';
const Template = require(templatePath).default;
const { head, html, css } = App.render({});
const data = Template.render({ includeJS, head, html });
const cssOptions = {};
const minifiedCss = new CleanCSS(cssOptions).minify(css.code).styles;
const htmlOptions = { collapseWhitespace: true };
const minifiedHtml = minify(data.html, htmlOptions);
fs.writeFileSync(path.join(outDir, 'index.html'), minifiedHtml, 'utf-8');
fs.writeFileSync(path.join(outDir, 'styles.css'), minifiedCss, 'utf-8');
fs.writeFileSync(path.join(outDir, 'styles.css.map'), css.map, 'utf-8');