mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-25 12:38:57 +02:00
feat(v2): introduce new minification of CSS bundle (#3716)
* feat(v2): optimize CSS bundle * Move to separate preset * Move custom scrollbar styles to separate class * Cleanup styles * Remove unactual styles * Various CSS optimizations, cleanup styles for NProgress * Add ability to back to old way of minifying CSS * chore(v2): downgrade babel-plugin-dynamic-import-node to 2.3.0 * Use env var for back to simple CSS minifier * remove unnecessary typing [skip-ci] * Remove missing dep * Update website/docs/cli.md Co-authored-by: Sébastien Lorber <slorber@users.noreply.github.com>
This commit is contained in:
parent
9afe4b5447
commit
487a9f98e4
20 changed files with 386 additions and 107 deletions
|
@ -0,0 +1,42 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const postcss = require('postcss');
|
||||
|
||||
/*
|
||||
This PostCSS plugin will remove duplicate/same custom properties (which are actually overridden ones) **only** from `:root` selector.
|
||||
|
||||
Depending on the presence of an `!important` rule in value of custom property, the following actions will happens:
|
||||
|
||||
- If the same custom properties do **not** have an `!important` rule, then all of them will be removed except for the last one (which will actually be applied).
|
||||
- If the same custom properties have at least one `!important` rule, then only those properties that do not have this rule will be removed.
|
||||
*/
|
||||
|
||||
module.exports = postcss.plugin(
|
||||
'postcss-remove-overridden-custom-properties',
|
||||
() => {
|
||||
return (root) => {
|
||||
root.walkDecls((decl) => {
|
||||
if (decl.parent.selector !== ':root') {
|
||||
return;
|
||||
}
|
||||
|
||||
const sameProperties =
|
||||
decl.parent.nodes.filter((n) => n.prop === decl.prop) || [];
|
||||
const hasImportantProperties = sameProperties.some((p) =>
|
||||
p.hasOwnProperty('important'),
|
||||
);
|
||||
|
||||
const overriddenProperties = hasImportantProperties
|
||||
? sameProperties.filter((p) => !p.hasOwnProperty('important'))
|
||||
: sameProperties.slice(0, -1);
|
||||
|
||||
overriddenProperties.map((p) => p.remove());
|
||||
});
|
||||
};
|
||||
},
|
||||
);
|
Loading…
Add table
Add a link
Reference in a new issue