Skip to content

Commit

Permalink
Require Node.js 14 and update dependencies
Browse files Browse the repository at this point in the history
Fixes #67
  • Loading branch information
sindresorhus committed Jan 24, 2023
1 parent 2a7dd5d commit 7403d1e
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 97 deletions.
3 changes: 0 additions & 3 deletions .github/funding.yml

This file was deleted.

9 changes: 4 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ jobs:
fail-fast: false
matrix:
node-version:
- 18
- 16
- 14
- 12
- 10
- 8
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
36 changes: 18 additions & 18 deletions gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,43 @@ module.exports = grunt => {
svgmin: {
compile: {
files: {
'test/tmp/test.svg': 'test/fixtures/test.svg'
}
'test/tmp/test.svg': 'test/fixtures/test.svg',
},
},
withconfig: {
options: {
plugins: [
{
removeViewBox: false
name: 'preset-default',
params: {
overrides: {
removeViewBox: false,
},
},
},
{
convertPathData: {
straightCurves: false
}
}
]
],
},
files: {
'test/tmp/withconfig.svg': 'test/fixtures/test.svg'
}
'test/tmp/withconfig.svg': 'test/fixtures/test.svg',
},
},
multiple: {
files: [{
expand: true,
cwd: 'test/fixtures/',
src: ['**/*.svg'],
dest: 'test/tmp/'
}]
}
dest: 'test/tmp/',
}],
},
},
simplemocha: {
test: {
src: 'test/*.js'
}
src: 'test/*.js',
},
},
clean: {
test: ['test/tmp']
}
test: ['test/tmp'],
},
});

grunt.loadTasks('tasks');
Expand Down
2 changes: 1 addition & 1 deletion license
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
20 changes: 13 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
"description": "Minify SVG",
"license": "MIT",
"repository": "sindresorhus/grunt-svgmin",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"engines": {
"node": ">=8"
"node": ">=14.16"
},
"scripts": {
"test": "xo && grunt"
Expand All @@ -28,19 +29,24 @@
"minify"
],
"dependencies": {
"chalk": "^2.4.2",
"log-symbols": "^2.2.0",
"pretty-bytes": "^5.1.0",
"svgo": "^1.2.0"
"chalk": "^4.1.2",
"log-symbols": "^4.1.0",
"pretty-bytes": "^5.6.0",
"svgo": "^3.0.2"
},
"devDependencies": {
"grunt": "^1.0.3",
"grunt-cli": "^1.3.2",
"grunt-contrib-clean": "^2.0.0",
"grunt-simple-mocha": "^0.4.1",
"xo": "^0.24.0"
"xo": "^0.53.1"
},
"peerDependencies": {
"grunt": ">=1"
},
"xo": {
"rules": {
"unicorn/prefer-module": "off"
}
}
}
60 changes: 9 additions & 51 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
*Issues with the output should be reported on the SVGO [issue tracker](https://github.com/svg/svgo/issues).*


## Install

```sh
npm install --save-dev grunt-svgmin
```
$ npm install --save-dev grunt-svgmin
```


## Usage

Expand All @@ -22,16 +20,11 @@ grunt.initConfig({
options: {
plugins: [
{
removeViewBox: false
},
{
removeUselessStrokeAndFill: false
},
{
removeAttrs: {
attrs: [
'xmlns'
]
name: 'preset-default',
params: {
overrides: {
sortAttrs: false
}
}
}
]
Expand All @@ -47,45 +40,10 @@ grunt.initConfig({
grunt.registerTask('default', ['svgmin']);
```

### Options

### Available Options/Plugins

This module makes use of the standard SVGO plugin architecture. Therefore, to customize SVG optimization, you can disable/enable/configure any SVGO plugins listed at the [SVGO repository](https://github.com/svg/svgo/tree/master/plugins).

To disable plugins with the gruntfile.js, look for the plugin name at the [SVGO repository](https://github.com/svg/svgo/tree/master/plugins) and copy the plugin name (minus the file extension). Then set its value in the JSON to `false` in comma-separated objects. To exemplify, here is how the plugins section in the example configuration (illustrated above) might be written with some of the standard SVGO plugins disabled:

```js
plugins: [
{removeViewBox: false}, // Don't remove the viewbox attribute from the SVG
{removeUselessStrokeAndFill: false}, // Don't remove Useless Strokes and Fills
{removeEmptyAttrs: false} // Don't remove Empty Attributes from the SVG
]
```

Check each plugin for `exports.active = [true/false]` to see if the plugin is enabled. Most of the plugins are enabled by default but you may want to prevent a couple, particularly `removeUselessStrokeAndFill` as that may remove small details with subtracted / extruded complex paths.

To configure specific parameters for a plugin with the gruntfile.js, set its value in the JSON to a `params` object:

```js
plugins: [
{
removeAttrs: {
attrs: [
'xmlns'
]
}
}
]
```

Check each plugin for `exports.params` to see if it has default parameters and what they are.

The provided options are passed directly to [SVGO](https://github.com/svg/svgo#configuration).

## Note

Per-file savings are only printed in verbose mode (`grunt svgmin --verbose`).


## License

MIT © [Sindre Sorhus](https://sindresorhus.com)
25 changes: 15 additions & 10 deletions tasks/svgmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,36 @@
const chalk = require('chalk');
const prettyBytes = require('pretty-bytes');
const logSymbols = require('log-symbols');
const SVGO = require('svgo');
const {optimize} = require('svgo');

module.exports = grunt => {
grunt.registerMultiTask('svgmin', 'Minify SVG', async function () {
const done = this.async();
const svgo = new SVGO(this.options());
const options = this.options();
let totalSavedBytes = 0;

await Promise.all(this.files.map(async element => {
const sourcePath = element.src[0];
for (const file of this.files) {
const sourcePath = file.src[0];
const sourceSvg = grunt.file.read(sourcePath);

const result = await svgo.optimize(sourceSvg, {path: sourcePath});
if (result.error) {
grunt.warn(`${sourcePath}: ${result.error}`);
return;
let result;
try {
result = optimize(sourceSvg, {
...options,
path: sourcePath,
});
} catch (error) {
grunt.warn(`${sourcePath}: ${error}`);
continue;
}

const savedBytes = sourceSvg.length - result.data.length;
const percentage = savedBytes / sourceSvg.length * 100;
totalSavedBytes += savedBytes;

grunt.verbose.writeln(logSymbols.success + ' ' + sourcePath + chalk.gray(' (saved ' + chalk.bold(prettyBytes(savedBytes)) + ' ' + Math.round(percentage) + '%)'));
grunt.file.write(element.dest, result.data);
}));
grunt.file.write(file.dest, result.data);
}

grunt.log.writeln(`Total saved: ${chalk.green(prettyBytes(totalSavedBytes))}`);
done();
Expand Down
4 changes: 2 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
/* eslint-env mocha */
const assert = require('assert');
const fs = require('fs');
const assert = require('node:assert');
const fs = require('node:fs');

it('minifies SVG', () => {
const original = fs.statSync('test/fixtures/test.svg').size;
Expand Down

0 comments on commit 7403d1e

Please sign in to comment.