-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
36 lines (31 loc) · 1005 Bytes
/
index.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
29
30
31
32
33
34
35
36
"use strict";
const fs = require("fs").promises;
const postcss = require('postcss');
const {parse} = require("postcss-scss");
const postcssPlugins = ["postcss-strip-inline-comments", "postcss-nested", "postcss-simple-vars", "postcss-color-function"].map((plugin) => require(plugin)());
let inputFile = `${__dirname}/src/style.css`;
let outputFile = `${__dirname}/build/bundle.css`;
function bundle() {
fs.readFile(inputFile, "utf-8").then((input) => {
return parse(input);
}).then((ast) => {
return postcss(postcssPlugins).process(ast, {
from: "style.css",
to: "bundle.css"
});
}).then((bundle) => {
return fs.writeFile(outputFile, bundle.css);
}).then(() => {
console.log("Finished writing CSS bundle");
});
}
if (process.env.NODE_ENV != "development") {
bundle();
} else {
const chokidar = require("chokidar");
const debounce = require("debounce");
console.log("Watching for changes");
chokidar.watch(`${__dirname}/src`).on("all", debounce(() => {
bundle();
}, 100));
}