Use cssnano to minify main CSS file (#569)

* Add cssnano to CSS generation

* Add babel-polyfill

* Call cssnano at the end

* Fix tests

* Add babelrc
This commit is contained in:
Yangshun Tay 2018-04-16 21:31:01 -07:00 committed by GitHub
parent 946e2cef90
commit 159b80df94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 1297 additions and 25 deletions

View file

@ -5,10 +5,11 @@
* LICENSE file in the root directory of this source tree.
*/
function execute() {
async function execute() {
const extractTranslations = require('../write-translations.js');
const CWD = process.cwd();
const cssnano = require('cssnano');
const fs = require('fs-extra');
const readMetadata = require('./readMetadata.js');
const path = require('path');
@ -371,7 +372,7 @@ function execute() {
}
});
// copy all static files from user
// Copy all static files from user.
files = glob.sync(join(CWD, 'static', '**'), {dot: true});
files.forEach(file => {
// Why normalize? In case we are on Windows.
@ -409,6 +410,18 @@ function execute() {
}
});
// Use cssnano to minify the final combined CSS.
const mainCss = join(buildDir, 'css', 'main.css');
const cssContent = fs.readFileSync(mainCss, 'utf8');
const {css} = await cssnano.process(
cssContent,
/* postcssOpts */ {},
/* cssnanoOpts */ {
preset: 'default',
}
);
fs.writeFileSync(mainCss, css);
// compile/copy pages from user
let pagesArr = [];
files = glob.sync(join(CWD, 'pages', '**'));