build: Add Grunt 'svgmin' task and crush SVGs

Adding 'grunt-svgmin' package and corresponding 'svgmin' task and
also crush in-use SVGs.

Bug: T215485
Change-Id: I3a8ba3daab7b7fb110000d88d9baff9ea1f5b5db
This commit is contained in:
Volker E 2019-02-06 22:25:33 -08:00
parent 3639907690
commit 523c7e0716
17 changed files with 549 additions and 509 deletions

View file

@ -5,6 +5,8 @@ module.exports = function ( grunt ) {
grunt.loadNpmTasks( 'grunt-eslint' );
grunt.loadNpmTasks( 'grunt-jsonlint' );
grunt.loadNpmTasks( 'grunt-stylelint' );
grunt.loadNpmTasks( 'grunt-svgmin' );
grunt.initConfig( {
eslint: {
all: [
@ -33,9 +35,46 @@ module.exports = function ( grunt ) {
'!node_modules/**',
'!vendor/**'
]
},
// SVG Optimization
svgmin: {
options: {
js2svg: {
indent: '\t',
pretty: true
},
multipass: true,
plugins: [ {
cleanupIDs: false
}, {
removeDesc: false
}, {
removeRasterImages: true
}, {
removeTitle: false
}, {
removeViewBox: false
}, {
removeXMLProcInst: false
}, {
sortAttrs: true
} ]
},
all: {
files: [ {
expand: true,
cwd: 'resources/images',
src: [
'**/*.svg'
],
dest: 'resources/images/',
ext: '.svg'
} ]
}
}
} );
grunt.registerTask( 'minify', 'svgmin' );
grunt.registerTask( 'test', [ 'eslint', 'jsonlint', 'banana', 'stylelint' ] );
grunt.registerTask( 'default', 'test' );
grunt.registerTask( 'default', [ 'minify', 'test' ] );
};

View file

@ -10,6 +10,7 @@
"grunt-eslint": "21.0.0",
"grunt-jsonlint": "1.1.0",
"grunt-stylelint": "0.10.1",
"grunt-svgmin": "5.0.0",
"stylelint-config-wikimedia": "0.5.0"
}
}

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" width="5" height="13" viewBox="0 0 1.323 3.44">
<path fill="#638c9c" d="M0 1.852v1.323h1.323V1.852z"/>
</svg>

Before

Width:  |  Height:  |  Size: 209 B

After

Width:  |  Height:  |  Size: 190 B

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="5" height="220" viewBox="0 0 1.323 58.208">
<defs>
<linearGradient id="b" x1="262.803" x2="263.049" y1="29.234" y2=".97" gradientTransform="translate(-492.003 238.792) scale(1.875)" gradientUnits="userSpaceOnUse" xlink:href="#a"/>

Before

Width:  |  Height:  |  Size: 658 B

After

Width:  |  Height:  |  Size: 597 B

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1941" height="220" viewBox="0 0 273.897 31.044">
<defs>
<linearGradient id="D">

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 4.233 4.233">
<defs>
<linearGradient id="b">

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 4.233 4.233">
<defs>
<radialGradient id="b" cx="2.117" cy="1.852" r="1.521" fx="2.117" fy="1.852" gradientTransform="matrix(1.04348 0 0 1 -.092 0)" gradientUnits="userSpaceOnUse" xlink:href="#a"/>
@ -10,8 +10,8 @@
</defs>
<path fill="url(#b)" fill-rule="evenodd" d="M.794 1.323l.264-.53.53-.264c.264-.264.793-.264 1.058 0l.529.265.265.529c.264.264.264.794 0 1.058l-.265.53-.53.264c-.264.265-.793.265-1.058 0l-.529-.265-.264-.529c-.265-.264-.265-.794 0-1.058z"/>
<path fill="#fff" d="M1.588 1.323h.265v.265h-.265z"/>
<path fill="#fff" d="M1.852 1.587v.53h.529v-.53h-.264zM2.381 2.117h.265v.265h-.265z"/>
<path fill="#fff" d="M2.381 1.323h.265v.265h-.265zM1.588 2.117h.265v.265h-.265z"/>
<path fill="#fff" d="M1.852 1.587v.53h.529v-.53h-.264zm.529.53h.265v.265h-.265z"/>
<path fill="#fff" d="M2.381 1.323h.265v.265h-.265zm-.793.794h.265v.265h-.265z"/>
<path fill="#faa" d="M1.587 1.058v.265h.265v-.265zm0 .265h-.264v.264h.264zm.794-.265v.265h.265v-.265zm.265.265v.264h.264v-.264zm-1.323.794v.264h.264v-.264zm.264.264v.265h.265V2.38zm1.059-.264v.264h.264v-.264zm0 .264H2.38v.265h.265z"/>
<path fill="#ffb5b5" d="M1.852 1.323v.264h.53v-.264zm.53.264v.53h.264v-.53zm0 .53h-.53v.264h.53zm-.53 0v-.53h-.265v.53z"/>
<path fill="#ffd5d5" d="M1.323 1.058v.265h.264v-.265zm1.323 0v.265h.264v-.265zM1.323 2.381v.265h.264V2.38zm1.323 0v.265h.264V2.38z"/>

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2 KiB

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 4.233 4.233">
<defs>
<linearGradient id="b">

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 4.233 4.233">
<defs>
<linearGradient id="b">
@ -13,7 +13,7 @@
<radialGradient id="c" cx="7.144" cy="1.587" r="1.521" fx="7.144" fy="1.587" gradientTransform="matrix(1.2174 0 0 .86957 -6.845 .207)" gradientUnits="userSpaceOnUse" xlink:href="#b"/>
</defs>
<path fill="url(#c)" fill-rule="evenodd" d="M.794 1.323l.264-.53.53-.264c.264-.264.793-.264 1.058 0l.529.265.265.529c.264.264.264.794 0 1.058l-.265.53-.53.264c-.264.265-.793.265-1.057 0l-.53-.265-.264-.529c-.265-.264-.265-.794 0-1.058z"/>
<path fill="url(#d)" fill-rule="evenodd" d="M2.117.397l-.53.132-.529.265-.132.264c.046.343.422.658.579.749.157.09.194.223.182.256-.013.033-.67.376-.761.583l.132.264.53.265.264.132.794-.132.264-.132-.264-.133s-.24-.002-.273-.15c-.033-.15.008-.379-.277-.602-.14-.11-.252-.066-.285-.136-.033-.07.07-.116.029-.199-.042-.083-.236-.136-.22-.244.017-.107.203.037.207-.029.004-.066-.004-.24.112-.244.205-.237.183-.594.178-.91zM2.91.66c-.181.096-.506.083-.529.302-.014.141-.019.405.104.624.184.331.514.291.616.253.122-.047.29-.248.47-.253l-.131-.264-.265-.53z"/>
<path fill="url(#d)" fill-rule="evenodd" d="M2.117.397l-.53.132-.529.265-.132.264c.046.343.422.658.579.749.157.09.194.223.182.256-.013.033-.67.376-.761.583l.132.264.53.265.264.132.794-.132.264-.132-.264-.133s-.24-.002-.273-.15c-.033-.15.008-.379-.277-.602-.14-.11-.252-.066-.285-.136-.033-.07.07-.116.029-.199-.042-.083-.236-.136-.22-.244.017-.107.203.037.207-.029.004-.066-.004-.24.112-.244.205-.237.183-.594.178-.91zM2.91.66c-.181.096-.506.083-.529.302-.014.141-.019.405.104.624a.513.513 0 0 0 .616.253c.122-.047.29-.248.47-.253l-.131-.264-.265-.53z"/>
<path fill="#8b8b8b" d="M1.588.265v.264h.793V.265zm0 .264h-.53v.265h.53zm-.53.265H.794v.529h.264zm-.264.529H.529V2.38h.265zm0 1.058v.53h.264v-.53zm.264.53v.264h.53V2.91zm.53.264v.265h.264v-.265z"/>
<path fill="#4e4e4e" d="M2.381.265v.264h.265V.265zm.265.264v.265h.529V.529zm.529.265v.529h.265v-.53zm.265.529V2.38h.264V1.323zm0 1.058h-.265v.53h.265zm-.265.53h-.53v.264h.53zm-.53.264h-.793v.265h.794z"/>
</svg>

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2 KiB

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 4.233 4.233">
<defs>
<linearGradient id="a">

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1 KiB

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 4.233 4.233">
<defs>
<linearGradient id="c">
@ -15,7 +15,7 @@
<stop offset="1" stop-color="#bdd7f3"/>
</linearGradient>
<radialGradient id="f" cx="12.249" cy="1.424" r=".728" fx="12.249" fy="1.424" gradientTransform="matrix(-.82724 -.02009 .02428 -.9997 12.12 3.422)" gradientUnits="userSpaceOnUse" xlink:href="#a"/>
<radialGradient id="e" cx="2.888" cy="2.578" r=".562" fx="2.888" fy="2.578" gradientTransform="matrix(.47059 -.47059 .94118 .94118 -.875 1.579)" gradientUnits="userSpaceOnUse" xlink:href="#b"/>
<radialGradient id="e" cx="2.888" cy="2.578" r=".562" fx="2.888" fy="2.578" gradientTransform="rotate(-45 1.469 1.846) scale(.66551 1.33104)" gradientUnits="userSpaceOnUse" xlink:href="#b"/>
<radialGradient id="d" cx="1.79" cy="1.499" r="1.224" fx="1.79" fy="1.499" gradientUnits="userSpaceOnUse" xlink:href="#c"/>
</defs>
<path fill="url(#d)" fill-rule="evenodd" d="M.794 1.058c-.265.265-.265.794 0 1.059l.529.529 1.19.132.53-.529-.133-1.19-.529-.53c-.264-.264-.793-.264-1.058 0z"/>

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 4.233 4.233">
<defs>
<linearGradient id="b">
@ -9,8 +9,8 @@
<stop offset="0" stop-color="#fef2d3"/>
<stop offset="1" stop-color="#fabd23"/>
</linearGradient>
<radialGradient id="c" cx="2.016" cy="2.35" r=".893" fx="2.016" fy="2.35" gradientTransform="matrix(.2963 .2963 -1.48148 1.48148 5.001 -1.962)" gradientUnits="userSpaceOnUse" xlink:href="#a"/>
<radialGradient id="d" cx="2.646" cy="2.646" r=".628" fx="2.646" fy="2.646" gradientTransform="matrix(.42105 -.42105 .7071 .7071 -.34 1.889)" gradientUnits="userSpaceOnUse" xlink:href="#b"/>
<radialGradient id="c" cx="2.016" cy="2.35" r=".893" fx="2.016" fy="2.35" gradientTransform="matrix(.2963 .2963 -1.48149 1.48149 5.001 -1.962)" gradientUnits="userSpaceOnUse" xlink:href="#a"/>
<radialGradient id="d" cx="2.646" cy="2.646" r=".628" fx="2.646" fy="2.646" gradientTransform="rotate(-45 2.11 1.355) scale(.59545 1)" gradientUnits="userSpaceOnUse" xlink:href="#b"/>
</defs>
<path fill="#e6e6e6" fill-rule="evenodd" d="M1.72 1.984l-.53-.529.265-.264.53.529z"/>
<path fill="url(#c)" fill-rule="evenodd" d="M1.852 1.852l-.794.794c-.264.264-.264.264 0 .529.265.265.265.265.53 0l1.058-1.058-.53-.53z"/>

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 4.233 4.233">
<defs>
<linearGradient id="a">

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 4.233 4.233">
<defs>
<linearGradient id="a">

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 4.233 4.233">
<defs>
<linearGradient id="a">

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 4.233 4.233">
<defs>
<linearGradient id="a">

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 4.233 4.233">
<defs>
<linearGradient id="c">

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB