-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* remove legacy svgo script * update svgo dep + new updated SVG minifier script * minify SVGs * update SVG paths to use *.mini.svg
- Loading branch information
Showing
108 changed files
with
180 additions
and
164 deletions.
There are no files selected for viewing
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,63 @@ | ||
import fs from 'node:fs/promises'; | ||
import { optimize } from 'svgo'; | ||
import { glob } from 'glob'; | ||
import path from 'node:path'; | ||
|
||
// Find non-minified SVG imports in codebase with regex search: (\S+(?<!\.mini)\.svg) | ||
|
||
const config = { | ||
multipass: true, | ||
plugins: [ | ||
{ | ||
name: 'preset-default', | ||
params: { | ||
overrides: { | ||
inlineStyles: { | ||
onlyMatchedOnce: false | ||
} | ||
} | ||
} | ||
}, | ||
'removeStyleElement' | ||
] | ||
}; | ||
|
||
const srcImages = await glob( | ||
['src/images/**/*.svg', 'static/images/**/*.svg'], | ||
{ ignore: '**/*.mini.svg' } | ||
); | ||
|
||
let bytesSaved = 0; | ||
|
||
const promises = srcImages.map(async (file) => { | ||
const data = await fs.readFile(file, 'utf-8'); | ||
const result = optimize(data, config); | ||
|
||
if (result.error) { | ||
console.error(result.error); | ||
process.exit(1); | ||
} | ||
|
||
const sizeDelta = result.data.length - data.length; | ||
bytesSaved += sizeDelta; | ||
|
||
console.log(file); | ||
console.log( | ||
sizeDelta <= 0 ? ' 🟢' : ' 🟡', | ||
`${((sizeDelta / data.length) * 100).toFixed(2)}%` | ||
); | ||
console.log(' ', (sizeDelta / 1024).toFixed(2), 'kB'); | ||
|
||
const { dir, name } = path.parse(file); | ||
const destinationFile = path.join(dir, `${name}.mini.svg`); | ||
|
||
await fs.writeFile(destinationFile, result.data, 'utf-8'); | ||
}); | ||
|
||
await Promise.all(promises); | ||
|
||
console.log( | ||
'Done!', | ||
(bytesSaved / 1024).toFixed(2), | ||
'kB size difference total' | ||
); |
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 |
---|---|---|
|
@@ -62,6 +62,6 @@ | |
"prettier": "^3.0.3", | ||
"sharp": "^0.32.6", | ||
"slugify": "^1.6.6", | ||
"svgo": "^3.0.2" | ||
"svgo": "^3.3.2" | ||
} | ||
} |
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
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
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.