forked from pie-inc/svelte-tailwindcss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprerender.js
More file actions
32 lines (25 loc) · 750 Bytes
/
prerender.js
File metadata and controls
32 lines (25 loc) · 750 Bytes
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
require('svelte/register')({
cssHash: ({ hash, css, name, filename }) => {
return `${hash(css)}`;
},
});
const { existsSync, promises } = require('fs');
const { join } = require('path');
const App = require('./src/App.svelte').default;
async function main() {
const templatePath = join(process.cwd(), 'src', 'template.html');
const publicPath = join(process.cwd(), 'public');
const template = await promises.readFile(templatePath);
const app = App.render();
if (!existsSync(publicPath)) {
await promises.mkdir(publicPath);
}
await promises.writeFile(
join(publicPath, 'index.html'),
template
.toString()
.replace('%svelte.head%', app.head)
.replace('%svelte.html%', app.html)
);
}
main();