Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/spotty-hornets-unite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/polaris-icons': minor
---

Added optimize script
5 changes: 3 additions & 2 deletions polaris-icons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
},
"scripts": {
"build": "rollup -c",
"clean": "rm -rf .turbo node_modules dist",
"dev": "rollup -c -w",
"test": "jest",
"clean": "rm -rf .turbo node_modules dist"
"optimize": "yarn svgo -f icons",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heads up @kyledurand and @samrose3, I don't think yarn is needed here. svgo's bin script should automatically be symlinked to node_modules/.bin and thus available to the run-script:
See here:

When this package is installed as a dependency in another package, the file will be linked where it will be available to that package either directly by npm exec or by name in other scripts when invoking them via npm run-script.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch and great point!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat!

"test": "jest"
},
"exports": {
".": {
Expand Down
43 changes: 1 addition & 42 deletions polaris-icons/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import globby from 'globby';
import jsYaml from 'js-yaml';
import svgr from '@svgr/core';
import {optimize} from 'svgo';
import svgoConfig from './svgo.config.js';

const convert = svgr.default;
const iconBasePath = new URL('./icons', import.meta.url).pathname;
Expand Down Expand Up @@ -101,48 +102,6 @@ function svgBuild(options = {}) {
const filter = createFilter(options.include || '**/*.svg', options.exclude);

/** @type {import('svgo').OptimizeOptions} */
const svgoConfig = {
plugins: [
{
name: 'preset-default',
params: {
overrides: {
/**
* viewBox is needed in order to produce 20px by 20px containers
* with smaller (minor) icons inside.
*/
removeViewBox: false,

/**
* The following 2 settings are disabled to reduce rendering inconsistency
* on Android. Android uses a subset of the SVG spec called SVG Tiny:
* https://developer.android.com/studio/write/vector-asset-studio#svg-support
*/

/**
* Merging mutliple detached paths into a single path can lead to
* rendering issues on some platforms where detatched paths are joined
* by hairlines. Not merging paths results in greater compatibility
* with minimal additional overhead.
*/
mergePaths: false,

convertPathData: {
/**
* Mixing absolute and relative path commands can lead to rendering
* issues on some platforms. This disables converting some path data to
* absolute if it is shorter, keeping all path data relative. Using
* relative paths means that data points are relative to the current
* point at the start of the path command, which does not greatly
* increase the quantity of path data.
*/
utilizeAbsolute: false,
},
},
},
},
],
};

svgoConfig.plugins.push({
...replaceFillAttributeSvgoPlugin(),
Expand Down
42 changes: 42 additions & 0 deletions polaris-icons/svgo.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module.exports = {
plugins: [
{
name: 'preset-default',
params: {
overrides: {
/**
* viewBox is needed in order to produce 20px by 20px containers
* with smaller (minor) icons inside.
*/
removeViewBox: false,

/**
* The following 2 settings are disabled to reduce rendering inconsistency
* on Android. Android uses a subset of the SVG spec called SVG Tiny:
* https://developer.android.com/studio/write/vector-asset-studio#svg-support
*/

/**
* Merging mutliple detached paths into a single path can lead to
* rendering issues on some platforms where detatched paths are joined
* by hairlines. Not merging paths results in greater compatibility
* with minimal additional overhead.
*/
mergePaths: false,

convertPathData: {
/**
* Mixing absolute and relative path commands can lead to rendering
* issues on some platforms. This disables converting some path data to
* absolute if it is shorter, keeping all path data relative. Using
* relative paths means that data points are relative to the current
* point at the start of the path command, which does not greatly
* increase the quantity of path data.
*/
utilizeAbsolute: false,
},
},
},
},
],
};