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');
|
|
|
|
|
2019-07-12 15:56:24 -04:00
|
|
|
const css = fs.readFileSync('css/src/all.css', 'utf-8');
|
|
|
|
const darkCss = fs.readFileSync('css/src/dark-override.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
|
|
|
|
const light = await postcss()
|
|
|
|
.use(atImport())
|
|
|
|
.use(cssNext(processOptions))
|
|
|
|
.use(cssNano(minOptions))
|
|
|
|
.process(css, {
|
|
|
|
from: 'css/src/all.css',
|
|
|
|
to: 'css/app.min.css',
|
|
|
|
});
|
|
|
|
fs.writeFileSync('css/app.min.css', light);
|
|
|
|
|
|
|
|
// Dark theme
|
|
|
|
const dark = await postcss()
|
|
|
|
.use(atImport())
|
|
|
|
.use(cssNext(processOptions))
|
|
|
|
.use(cssNano(minOptions))
|
|
|
|
.process(darkCss, {
|
|
|
|
from: 'css/dark-override.css',
|
|
|
|
to: 'css/dark.min.css',
|
|
|
|
});
|
|
|
|
fs.writeFileSync('css/dark.min.css', dark);
|
|
|
|
|
|
|
|
const autoDarkCss = `${light} @media (prefers-color-scheme: dark) { ${dark} }`
|
|
|
|
fs.writeFileSync('css/dark-auto.min.css', autoDarkCss)
|
|
|
|
|
|
|
|
})();
|