HummingBirdAnimeClient/frontEndSrc/css.js

71 lines
1.7 KiB
JavaScript
Raw Permalink Normal View History

/**
* Script for optimizing css
*/
const fs = require('fs');
const postcss = require('postcss');
const atImport = require('postcss-import');
const cssNext = require('postcss-preset-env');
const cssNano = require('cssnano');
const lightCss = fs.readFileSync('css/light.css', 'utf-8');
const darkCss = fs.readFileSync('css/src/dark-override.css', 'utf-8');
const fullDarkCss = fs.readFileSync('css/dark.css', 'utf-8');
const minOptions = {
autoprefixer: false,
colormin: false,
minifyFontValues: false,
options: {
sourcemap: false
}
};
2018-12-06 13:04:54 -05:00
const processOptions = {
browser: '> 0.5%',
features: {
'custom-properties': true,
},
stage: 0,
};
2020-04-23 18:51:12 -04:00
try {
(async () => {
// Basic theme
const lightMin = await postcss()
.use(atImport())
.use(cssNext(processOptions))
.use(cssNano(minOptions))
.process(lightCss, {
from: 'css/light.css',
to: '/public/css/light.min.css',
2020-04-23 18:51:12 -04:00
}).catch(console.error);
fs.writeFileSync('../public/css/light.min.css', lightMin.css);
2020-04-23 18:51:12 -04:00
// Dark theme
const darkFullMin = await postcss()
.use(atImport())
.use(cssNext(processOptions))
.use(cssNano(minOptions))
.process(fullDarkCss, {
from: 'css/dark.css',
to: '/public/css/dark.min.css',
});
fs.writeFileSync('../public/css/dark.min.css', darkFullMin.css);
2020-04-23 18:51:12 -04:00
// Dark override
const darkMin = await postcss()
.use(atImport())
.use(cssNext(processOptions))
.use(cssNano(minOptions))
.process(darkCss, {
from: 'css/dark-override.css',
to: '/public/css/dark.min.css',
}).catch(console.error);
const autoDarkCss = `${lightMin} @media (prefers-color-scheme: dark) { ${darkMin.css} }`
fs.writeFileSync('../public/css/auto.min.css', autoDarkCss)
2020-04-23 18:51:12 -04:00
})();
} catch (e) {
console.error(e)
}