mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 23:57:22 +02:00
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:
parent
946e2cef90
commit
159b80df94
7 changed files with 1297 additions and 25 deletions
|
@ -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', '**'));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue