Skip to content

Commit

Permalink
Update the SVG sprite creation to use SVGO v2 (#688)
Browse files Browse the repository at this point in the history
  • Loading branch information
scriptex authored Jun 1, 2021
1 parent 6954391 commit ebc60de
Show file tree
Hide file tree
Showing 4 changed files with 409 additions and 499 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webpack-mpa",
"version": "3.7.1",
"version": "3.8.0",
"description": "Multi page app setup with webpack",
"scripts": {
"build": "webpack --mode=production",
Expand Down Expand Up @@ -39,6 +39,7 @@
"babel-loader": "8.2.2",
"browser-sync": "2.26.14",
"browser-sync-webpack-plugin": "2.3.0",
"browserslist": "4.16.6",
"clean-webpack-plugin": "1.0.1",
"create-pwa": "2.3.1",
"critical": "3.1.0",
Expand All @@ -64,6 +65,7 @@
"spritesh": "1.2.1",
"stylelint": "13.13.1",
"stylelint-config-recommended": "5.0.0",
"svgo": "2.3.0",
"webpack": "5.38.1",
"webpack-cli": "4.7.0",
"webpack-shell-plugin-next": "2.2.2",
Expand Down
77 changes: 77 additions & 0 deletions svgo.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// @ts-nocheck

const { extendDefaultPlugins } = require('svgo');

module.exports = {
plugins: extendDefaultPlugins([
{
name: 'cleanupAttrs',
active: true
},
{
name: 'removeDoctype',
active: true
},
{
name: 'removeXMLProcInst',
active: true
},
{
name: 'removeComments',
active: true
},
{
name: 'removeMetadata',
active: true
},
{
name: 'removeUselessDefs',
active: true
},
{
name: 'removeEditorsNSData',
active: true
},
{
name: 'removeEmptyAttrs',
active: true
},
{
name: 'removeEmptyText',
active: true
},
{
name: 'removeEmptyContainers',
active: true
},
{
name: 'cleanupEnableBackground',
active: true
},
{
name: 'convertStyleToAttrs',
active: true
},
{
name: 'removeUselessStrokeAndFill',
active: true
},
{
name: 'cleanupIDs',
active: true,
params: {
prefix: {
toString() {
this.counter = this.counter || 0;

return `svgo-viewbox-id-${this.counter++}`;
}
}
}
},
{
name: 'removeDimensions',
active: true
}
])
};
23 changes: 1 addition & 22 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,6 @@ if (server) {
exec('php index.php > index.html');
}

const svgoConfig = {
plugins: [
{ name: 'cleanupAttrs', active: true },
{ name: 'removeDoctype', active: true },
{ name: 'removeXMLProcInst', active: true },
{ name: 'removeComments', active: true },
{ name: 'removeMetadata', active: true },
{ name: 'removeUselessDefs', active: true },
{ name: 'removeEditorsNSData', active: true },
{ name: 'removeEmptyAttrs', active: true },
{ name: 'removeHiddenElems', active: false },
{ name: 'removeEmptyText', active: true },
{ name: 'removeEmptyContainers', active: true },
{ name: 'cleanupEnableBackground', active: true },
{ name: 'removeViewBox', active: false },
{ name: 'cleanupIDs', active: false },
{ name: 'convertStyleToAttrs', active: true },
{ name: 'removeUselessStrokeAndFill', active: true }
]
};

const postcssOptions = {
plugins: [
require('postcss-easy-import'),
Expand Down Expand Up @@ -136,7 +115,7 @@ const shellScripts = [];
const svgs = readdirSync('./assets/images/svg').filter(svg => svg[0] !== '.');

if (svgs.length) {
shellScripts.push('svgo -f assets/images/svg --config=' + JSON.stringify(svgoConfig));
shellScripts.push('svgo -f assets/images/svg');
shellScripts.push('spritesh -q -i assets/images/svg -o ./assets/dist/sprite.svg -p svg-');
}

Expand Down
Loading

0 comments on commit ebc60de

Please sign in to comment.