aboutsummaryrefslogtreecommitdiffstats
path: root/app/builder/processCss.ts
blob: 24aa3cf0c60a477e3b42959a3b797b6a54068bf2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import fs from 'fs';
import * as sass from 'sass';
import CleanCSS from 'clean-css';

const cleanCss = new CleanCSS({ returnPromise: true });

export async function process(file: string): Promise<string> {
    const scss = file.endsWith('.scss');
    
    const content = fs.readFileSync(file, 'utf-8').toString();

    let css: string;
    if (scss) {
        css = sass.compileString(content).css;
    } else {
        css = content;
    }

    const minified = (await cleanCss.minify(css)).styles;

    return minified;
}