mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-29 14:38:50 +02:00
feat(v2): minify css (#1572)
* feat(v2): minify css * fix docusaurus.js logic
This commit is contained in:
parent
f0d5313d48
commit
f07791b303
4 changed files with 503 additions and 18 deletions
|
@ -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",
|
||||
|
|
|
@ -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;
|
||||
},
|
||||
|
|
|
@ -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: {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue