2017-04-06 11:45:25 -04:00
|
|
|
/**
|
|
|
|
* Script for optimizing css
|
|
|
|
*/
|
|
|
|
const fs = require('fs');
|
|
|
|
const postcss = require('postcss');
|
|
|
|
const atImport = require('postcss-import');
|
2019-07-12 15:56:24 -04:00
|
|
|
const cssNext = require('postcss-preset-env');
|
2017-04-06 11:45:25 -04:00
|
|
|
const cssNano = require('cssnano');
|
|
|
|
|
2020-04-10 15:07:08 -04:00
|
|
|
const lightCss = fs.readFileSync('css/light.css', 'utf-8');
|
2019-07-12 15:56:24 -04:00
|
|
|
const darkCss = fs.readFileSync('css/src/dark-override.css', 'utf-8');
|
2020-04-10 15:07:08 -04:00
|
|
|
const fullDarkCss = fs.readFileSync('css/dark.css', 'utf-8');
|
2017-04-06 11:45:25 -04:00
|
|
|
|
2019-07-12 15:56:24 -04:00
|
|
|
const minOptions = {
|
|
|
|
autoprefixer: false,
|
|
|
|
colormin: false,
|
|
|
|
minifyFontValues: false,
|
|
|
|
options: {
|
|
|
|
sourcemap: false
|
|
|
|
}
|
|
|
|
};
|
2018-12-06 13:04:54 -05:00
|
|
|
|
2019-07-12 15:56:24 -04:00
|
|
|
const processOptions = {
|
|
|
|
browser: '> 0.5%',
|
|
|
|
features: {
|
|
|
|
'custom-properties': true,
|
|
|
|
},
|
|
|
|
stage: 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
(async () => {
|
|
|
|
// Basic theme
|
2020-04-10 15:07:08 -04:00
|
|
|
const lightMin = await postcss()
|
2019-07-12 15:56:24 -04:00
|
|
|
.use(atImport())
|
|
|
|
.use(cssNext(processOptions))
|
|
|
|
.use(cssNano(minOptions))
|
2020-04-10 15:07:08 -04:00
|
|
|
.process(lightCss, {
|
|
|
|
from: 'css/light.css',
|
|
|
|
to: '/public/css/light.min.css',
|
2019-07-12 15:56:24 -04:00
|
|
|
});
|
2020-04-10 15:07:08 -04:00
|
|
|
fs.writeFileSync('../public/css/light.min.css', lightMin);
|
2019-07-12 15:56:24 -04:00
|
|
|
|
|
|
|
// Dark theme
|
2020-04-10 15:07:08 -04:00
|
|
|
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);
|
|
|
|
|
|
|
|
// Dark override
|
|
|
|
const darkMin = await postcss()
|
2019-07-12 15:56:24 -04:00
|
|
|
.use(atImport())
|
|
|
|
.use(cssNext(processOptions))
|
|
|
|
.use(cssNano(minOptions))
|
|
|
|
.process(darkCss, {
|
|
|
|
from: 'css/dark-override.css',
|
2020-04-10 15:07:08 -04:00
|
|
|
to: '/public/css/dark.min.css',
|
2019-07-12 15:56:24 -04:00
|
|
|
});
|
2020-04-10 15:07:08 -04:00
|
|
|
const autoDarkCss = `${lightMin} @media (prefers-color-scheme: dark) { ${darkMin} }`
|
|
|
|
fs.writeFileSync('../public/css/auto.min.css', autoDarkCss)
|
2019-07-12 15:56:24 -04:00
|
|
|
|
|
|
|
})();
|