From f3d48beef7397fc95d5c6112e5432ecc6f5db0df Mon Sep 17 00:00:00 2001 From: Volker E Date: Mon, 12 Feb 2018 12:01:28 -0800 Subject: [PATCH] build: Bring SVGO optimization to build step Enabling SVGO automation with 'grunt-svgmin' and conservative plugin settings to build step, among those: - enable removeRasterImages and sortAttrs, - disable cleanupIDs, removeDesc, removeTitle, removeViewBox & removeXMLProcInst and - make use of pretty, indent and multipass options. Also updating SVG accordingly. Bug: T185596 Change-Id: I0030a711a2947ca8c1eb4e56d8540661c72a2639 --- Gruntfile.js | 42 ++++++++++++++++++++-- package.json | 1 + resources/images/cog-sprite.svg | 4 +-- resources/images/cog.svg | 2 +- resources/images/compact-links-ltr.svg | 12 +++---- resources/images/compact-links-rtl.svg | 12 +++---- resources/images/compact-links-trigger.svg | 2 +- resources/images/display.svg | 2 +- resources/images/help.svg | 2 +- resources/images/input.svg | 2 +- resources/images/remove-input.svg | 4 +-- 11 files changed, 60 insertions(+), 25 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index aaf8fec6..3aa3dad9 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -6,6 +6,7 @@ module.exports = function ( grunt ) { grunt.loadNpmTasks( 'grunt-eslint' ); grunt.loadNpmTasks( 'grunt-jsonlint' ); grunt.loadNpmTasks( 'grunt-stylelint' ); + grunt.loadNpmTasks( 'grunt-svgmin' ); grunt.initConfig( { eslint: { @@ -36,9 +37,46 @@ module.exports = function ( grunt ) { '!vendor/**' ] }, - banana: conf.MessagesDirs + banana: conf.MessagesDirs, + // SVG Optimization + svgmin: { + options: { + js2svg: { + indent: ' ', + 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', 'stylelint', 'jsonlint', 'banana' ] ); - grunt.registerTask( 'default', 'test' ); + grunt.registerTask( 'default', [ 'minify', 'test' ] ); }; diff --git a/package.json b/package.json index 3dcc2ca6..276964aa 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "grunt-eslint": "20.1.0", "grunt-jsonlint": "1.1.0", "grunt-stylelint": "0.9.0", + "grunt-svgmin": "5.0.0", "stylelint": "8.2.0", "stylelint-config-wikimedia": "0.4.2" } diff --git a/resources/images/cog-sprite.svg b/resources/images/cog-sprite.svg index eaca444a..28621287 100644 --- a/resources/images/cog-sprite.svg +++ b/resources/images/cog-sprite.svg @@ -1,7 +1,7 @@ - + - + diff --git a/resources/images/cog.svg b/resources/images/cog.svg index 91968ee9..ad8165b0 100644 --- a/resources/images/cog.svg +++ b/resources/images/cog.svg @@ -1,4 +1,4 @@ - + diff --git a/resources/images/compact-links-ltr.svg b/resources/images/compact-links-ltr.svg index 18bf0986..65ef981c 100644 --- a/resources/images/compact-links-ltr.svg +++ b/resources/images/compact-links-ltr.svg @@ -5,16 +5,14 @@ - + - + - - - - - + + + diff --git a/resources/images/compact-links-rtl.svg b/resources/images/compact-links-rtl.svg index a132e6e4..0fd7bc02 100644 --- a/resources/images/compact-links-rtl.svg +++ b/resources/images/compact-links-rtl.svg @@ -5,16 +5,14 @@ - + - + - - - - - + + + diff --git a/resources/images/compact-links-trigger.svg b/resources/images/compact-links-trigger.svg index 728036db..3a62fe8c 100644 --- a/resources/images/compact-links-trigger.svg +++ b/resources/images/compact-links-trigger.svg @@ -1,4 +1,4 @@ - + diff --git a/resources/images/display.svg b/resources/images/display.svg index e41633bc..098503cb 100644 --- a/resources/images/display.svg +++ b/resources/images/display.svg @@ -1,4 +1,4 @@ - + diff --git a/resources/images/help.svg b/resources/images/help.svg index c8cf6e6f..c2b741a6 100644 --- a/resources/images/help.svg +++ b/resources/images/help.svg @@ -1,4 +1,4 @@ - + diff --git a/resources/images/input.svg b/resources/images/input.svg index bac7a761..b0dac628 100644 --- a/resources/images/input.svg +++ b/resources/images/input.svg @@ -1,4 +1,4 @@ - + diff --git a/resources/images/remove-input.svg b/resources/images/remove-input.svg index d6270540..a192a26b 100644 --- a/resources/images/remove-input.svg +++ b/resources/images/remove-input.svg @@ -1,5 +1,5 @@ - - + +