Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
build: Replace 'grunt-svgmin' with npm based 'svgo'
Browse files Browse the repository at this point in the history
Replacing 'grunt-svgmin' with 'svgo' v2.8.0.
Also
- replacing Grunt based task with npm equivalent including excluded
  SVG file.
- changing to JS based '.svgo.config.js'

Bug: [T246321](https://phabricator.wikimedia.org/T246321)
Bug: [T278656](https://phabricator.wikimedia.org/T278656)
  • Loading branch information
Volker-E committed Feb 6, 2022
1 parent 3c052d5 commit a1f1841
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 608 deletions.
40 changes: 40 additions & 0 deletions .svgo.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* SVGO Configuration
* Compatible to v2.4.0+
* Recommended options from:
* https://www.mediawiki.org/wiki/Manual:Coding_conventions/SVG#Exemplified_safe_configuration
*/
module.exports = {
plugins: [
{
// Set of built-in plugins enabled by default.
name: 'preset-default',
params: {
overrides: {
cleanupIDs: false,
removeDesc: false,
removeTitle: false,
removeViewBox: false,
// If the SVG doesn't start with an XML declaration, then its MIME type will
// be detected as "text/plain" rather than "image/svg+xml" by libmagic and,
// consequently, MediaWiki's CSSMin CSS minifier. libmagic's default database
// currently requires that SVGs contain an XML declaration:
// https://github.com/threatstack/libmagic/blob/master/magic/Magdir/sgml#L5
removeXMLProcInst: false
}
}
},
'removeRasterImages',
'sortAttrs'
],
// Set whitespace according to Wikimedia Coding Conventions.
// @see https://github.com/svg/svgo/blob/main/lib/svgo/coa.js#L194 for more config options
js2svg: {
eol: 'lf',
finalNewline: true,
// Configure the indent to tabs (default 4 spaces) used by `--pretty` here.
indent: '\t',
pretty: true
},
multipass: true
}
39 changes: 0 additions & 39 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ module.exports = function ( grunt ) {
grunt.loadNpmTasks( '@lodder/grunt-postcss' );
grunt.loadNpmTasks( 'grunt-replace' );
grunt.loadNpmTasks( 'grunt-stylelint' );
grunt.loadNpmTasks( 'grunt-svgmin' );

grunt.initConfig( {
// Build – JavaScript
Expand Down Expand Up @@ -108,43 +107,6 @@ module.exports = function ( grunt ) {
}
},

svgmin: {
options: {
js2svg: {
indent: '\t',
multipass: true,
pretty: true
},
plugins: [ {
cleanupIDs: false
}, {
removeDesc: true
}, {
removeRasterImages: true
}, {
removeTitle: false
}, {
removeViewBox: false
}, {
removeXMLProcInst: false
}, {
sortAttrs: true
} ]
},
all: {
files: [ {
expand: true,
cwd: './',
src: [
'**/*.svg',
'!img/visual-style/principles-paper-ink.svg'
],
dest: './',
ext: '.svg'
} ]
}
},

replace: {
dist: {
options: {
Expand Down Expand Up @@ -183,7 +145,6 @@ module.exports = function ( grunt ) {
} );

grunt.registerTask( 'lint', [ 'eslint', 'stylelint' ] );
grunt.registerTask( 'images', [ 'svgmin' ] );
grunt.registerTask( 'images-pre-production', [ 'replace' ] );
grunt.registerTask( 'default', [ 'concat', 'uglify', 'postcss:dev', 'postcss:min' ] );
};
Loading

0 comments on commit a1f1841

Please sign in to comment.