-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ts
38 lines (31 loc) · 893 Bytes
/
build.ts
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
35
36
37
38
import React from 'react';
import ReactDOM from 'react-dom/server';
import fs from 'fs';
import { PurgeCSS } from 'purgecss';
import createCleanCss from 'clean-css';
import { Wrapper } from './src/Wrapper';
import { StyleMeta } from '@bdxtown/canaille';
const cleancss = new createCleanCss();
async function generate() {
const markup = `
<!DOCTYPE html>
${ReactDOM.renderToStaticMarkup(React.createElement(Wrapper))}
`;
const css = StyleMeta.getServerSideStyle();
const output = await new PurgeCSS().purge({
content: [
{
raw: markup,
extension: 'html'
},
],
css: [
{
raw: css
}
]
})
fs.writeFileSync('index.html', markup);
fs.writeFileSync('ssr.css', cleancss.minify(output[0].css).styles.replace(/@layer components/g, '@layer cmps'));
}
generate();