feat(v2): minify css (#1572)

* feat(v2): minify css

* fix docusaurus.js logic
This commit is contained in:
Endi 2019-06-06 18:00:43 +07:00 committed by GitHub
parent f0d5313d48
commit f07791b303
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 503 additions and 18 deletions

View file

@ -56,6 +56,7 @@
"mini-css-extract-plugin": "^0.4.1",
"nprogress": "^0.2.0",
"null-loader": "^2.0.0",
"optimize-css-assets-webpack-plugin": "^5.0.1",
"portfinder": "^1.0.13",
"react-dev-utils": "^9.0.1",
"react-helmet": "^6.0.0-beta",

View file

@ -12,23 +12,29 @@ import preloadHelper from './preload';
import flat from './flat';
const fetched = {};
const loaded = {};
const canPrefetchOrLoad = routePath => {
const isSlowConnection = () => {
// if user is on slow or constrained connection
if (`connection` in navigator) {
if ((navigator.connection.effectiveType || ``).includes(`2g`)) {
return false;
}
if (navigator.connection.saveData) {
return false;
if (
(navigator.connection.effectiveType || ``).includes(`2g`) &&
navigator.connection.saveData
) {
return true;
}
}
return !fetched[routePath];
return false;
};
const canPrefetch = routePath =>
!isSlowConnection() && !loaded[routePath] && !fetched[routePath];
const canPreload = routePath => !isSlowConnection() && !loaded[routePath];
const docusaurus = {
prefetch: routePath => {
if (!canPrefetchOrLoad(routePath)) {
if (!canPrefetch(routePath)) {
return false;
}
@ -56,10 +62,10 @@ const docusaurus = {
return true;
},
preload: routePath => {
if (!canPrefetchOrLoad(routePath)) {
if (!canPreload(routePath)) {
return false;
}
fetched[routePath] = true;
loaded[routePath] = true;
preloadHelper(routes, routePath);
return true;
},

View file

@ -6,6 +6,7 @@
*/
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import OptimizeCSSAssetsPlugin from 'optimize-css-assets-webpack-plugin';
import TerserPlugin from 'terser-webpack-plugin';
import path from 'path';
import fs from 'fs-extra';
@ -73,6 +74,11 @@ export function createBaseConfig(
},
},
}),
new OptimizeCSSAssetsPlugin({
cssProcessorPluginOptions: {
preset: 'default',
},
}),
]
: undefined,
splitChunks: {