-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat-noto-sans-eu
- Loading branch information
Showing
6 changed files
with
133 additions
and
58 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Performance | ||
|
||
If you need to improve the performance of your application, you can use the following tips: | ||
|
||
## Minify with PurgeCSS and CSSO | ||
|
||
When you use the full bundled `.css` file we provide, you could easily reduce the file size by removing unused CSS classes. This can be done with [PurgeCSS](https://purgecss.com/) and [CSSO](https://github.com/css/csso). | ||
|
||
Install both with: | ||
|
||
```shell | ||
npm i purgecss csso --save-dev | ||
``` | ||
|
||
Next you should create a file, e.g. `purgecss.js` in your project root with the following content: | ||
|
||
```javascript | ||
import { writeFileSync } from "node:fs"; | ||
|
||
import { PurgeCSS } from "purgecss"; | ||
import { minify } from "csso"; | ||
|
||
const distFolder = "dist"; // TODO: Change me if you need another folder | ||
|
||
new PurgeCSS() | ||
.purge({ | ||
content: [`${distFolder}/**/*.html`, `${distFolder}/**/*.js`], | ||
css: [`${distFolder}/**/*.css`], | ||
defaultExtractor: (content) => content.match(/[\w-/:]+(?<!:)/g) || [], | ||
variables: true, | ||
rejectedCss: true, | ||
safelist: { | ||
variables: [ | ||
/* TODO: Keep only the densities you need */ | ||
/-functional-/, | ||
/-regular-/, | ||
/-expressive-/, | ||
/* Keep density & all color properties/variables */ | ||
/-default$/, | ||
/-hovered$/, | ||
/-pressed$/ | ||
], | ||
/* Some components require a safelist */ | ||
greedy: [ | ||
/db-tabs/ // TODO: Add more components if necessary | ||
] | ||
} | ||
}) | ||
.then((purgeCSSResult) => { | ||
for (const result of purgeCSSResult) { | ||
writeFileSync(result.file, minify(result.css).css); | ||
|
||
/* Optional: for debugging */ | ||
// writeFileSync(`rejected.css`, result.rejectedCss || ""); | ||
} | ||
}); | ||
``` | ||
|
||
You can run this script with `node purgecss.js` and it will minify your CSS files. You can also add this script to your `package.json` to run after your regular build process: | ||
|
||
```json | ||
{ | ||
"scripts": { | ||
"postbuild": "node purgecss.js" | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import DefaultPage from "../../../components/default-page"; | ||
|
||
import Readme from "../../../../../packages/foundations/docs/Performance.md"; | ||
|
||
<Readme /> | ||
|
||
export default ({ children }) => <DefaultPage>{children}</DefaultPage>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters