Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

t/ckeditor5-theme-lark/206: Created an npm task that cleans up SVG icons. Updated docs. #1361

Merged
merged 7 commits into from
Nov 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions docs/framework/guides/contributing/development-environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,22 @@ Leads to [`ckeditor/ckeditor5-image@02869eb`](https://github.com/ckeditor/ckedit

By default, CKEditor 5 supports SVG icons found in the `ckeditor5-*/theme/icons` folders. Unfortunately, most of the SVG editing software produces the output with comments, obsolete tags, and complex paths, which bloats the DOM and makes the builds heavy for no good reason.

To remove the excess data and prevent [certain issues](https://github.com/ckeditor/ckeditor5-ui/issues/245), **all new icons should be optimized before joining the code base**. The right utility to do this is Node–based [SVGO](https://github.com/svg/svgo) and the usage is as simple as:
To remove the excess data and prevent [certain issues](https://github.com/ckeditor/ckeditor5-ui/issues/245), **all new icons should be optimized before joining the code base**. To do that, you can use the `clean-up-svg-icons` script in the [root of the project](#setting-up-the-ckeditor-development-environment), a wrapper for the [SVGO](https://github.com/svg/svgo) tool:

```bash
npm install -g svgo
cd ckeditor5-package-name/theme/icons
svgo --enable removeTitle -i .
cd path/to/ckeditor5

# Optimize all SVG files in the folder.
npm run clean-up-svg-icons path/to/icons/*.svg

# Optimize a single SVG file.
npm run clean-up-svg-icons path/to/icon/icon.svg
```

SVGO reduces the icon size up to 70%, depending on the software used to create it and the general complexity of the image.
The script reduces the icon size up to 70%, depending on the software used to create it and the general complexity of the image.

**Note**: You may still need to tweak the source code of the SVG files manually after using the script:

* The icons should have the `viewBox` attribute (instead of `width` and `height`). The `removeDimensions` SVGO plugin will not remove `width` and `height` if there is no `viewBox` attribute so make sure it is present.
* Sometimes SVGO leaves empty (transparent) groups `<g>...</g>`. They should be removed from the source.
* Make sure the number of `<path>` elements is minimal. Merge paths whenever possible in the image processor before saving the file.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"postcss-loader": "^3.0.0",
"raw-loader": "^0.5.1",
"style-loader": "^0.23.0",
"svgo": "^1.1.0",
"uglifyjs-webpack-plugin": "^1.2.7",
"umberto": "^0.12.0",
"webpack": "^4.15.0"
Expand Down Expand Up @@ -115,7 +116,8 @@
"release:bump-version": "node ./scripts/release/bump-versions.js",
"release:publish": "node ./scripts/release/publish.js",
"release:stable-branches": "sh ./scripts/update-stable-branches.sh",
"switch-to-dev-dev": "sh ./scripts/switch-to-dev-dev.sh"
"switch-to-dev-dev": "sh ./scripts/switch-to-dev-dev.sh",
"clean-up-svg-icons": "sh ./scripts/clean-up-svg-icons.sh"
},
"lint-staged": {
"**/*.js": [
Expand Down
15 changes: 15 additions & 0 deletions scripts/clean-up-svg-icons.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

# @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
# For licensing, see LICENSE.md.

# Cleans up and optimizes SVG files using the SVGO utility.
# The configuration file is located in svgo.config.json.
#
# Usage:
# npm run clean-up-svg-icons path/to/icons/*.svg

for i in "$@"
do
svgo --config=./scripts/svgo.config.json -i $i
done
10 changes: 10 additions & 0 deletions scripts/svgo.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"plugins": [
"collapseGroups",
"removeDimensions",
{ "removeAttrs": { "attrs": "(fill|stroke|fill-rule)" } },
"removeTitle",
"removeComments",
"removeMetadata"
]
}