Socket
Socket
Sign inDemoInstall

gulp-svgmin

Package Overview
Dependencies
28
Maintainers
2
Versions
36
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.0 to 4.0.0

dist/get-svgo-config.js

63

dist/index.js

@@ -1,49 +0,46 @@

'use strict';
"use strict";
var _stream = require('stream');
var _pluginError = _interopRequireDefault(require("plugin-error"));
var _svgo = require('svgo');
var _stream = require("stream");
var _svgo2 = _interopRequireDefault(_svgo);
var _svgo = require("svgo");
var _pluginError = require('plugin-error');
var _getSvgoConfig = require("./get-svgo-config.js");
var _pluginError2 = _interopRequireDefault(_pluginError);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var PLUGIN_NAME = 'gulp-svgmin';
const PLUGIN_NAME = 'gulp-svgmin';
module.exports = function (opts) {
var stream = new _stream.Transform({ objectMode: true });
var svgo = void 0;
module.exports = function (options) {
const optionsFunction = typeof options === 'function';
const stream = new _stream.Transform({
objectMode: true
});
if (typeof opts !== 'function') {
svgo = new _svgo2.default(opts);
stream._transform = function (file, encoding, cb) {
if (file.isStream()) {
return cb(new _pluginError.default(PLUGIN_NAME, 'Streaming not supported'));
}
stream._transform = function (file, encoding, cb) {
if (file.isNull()) {
return cb(null, file);
}
if (file.isBuffer()) {
(0, _getSvgoConfig.getSvgoConfig)(optionsFunction ? options(file) : options, optionsFunction).then(config => {
const result = (0, _svgo.optimize)(String(file.contents), config); // Ignore svgo meta data and return the SVG string.
if (file.isStream()) {
return cb(new _pluginError2.default(PLUGIN_NAME, 'Streaming not supported'));
}
if (typeof result.data === 'string') {
file.contents = Buffer.from(result.data);
return cb(null, file);
} // Otherwise, throw an error, even if it is undefined.
if (file.isBuffer()) {
if (typeof opts === 'function') {
svgo = new _svgo2.default(opts(file));
}
svgo.optimize(String(file.contents)).then(function (result) {
file.contents = Buffer.from(result.data);
cb(null, file);
}, function (error) {
cb(new _pluginError2.default(PLUGIN_NAME, error));
});
}
};
throw result.error;
}).catch(error => cb(new _pluginError.default(PLUGIN_NAME, error)));
return;
} // Handle all other cases, like file.isNull(), file.isDirectory().
return stream;
return cb(null, file);
};
return stream;
};
{
"name": "gulp-svgmin",
"version": "3.0.0",
"version": "4.0.0",
"description": "Minify SVG files with gulp.",

@@ -10,9 +10,9 @@ "license": "MIT",

"email": "beneb.info@gmail.com",
"url": "http://beneb.info"
"url": "https://beneb.info"
},
"main": "dist/index.js",
"scripts": {
"pretest": "eslint src",
"prepublishOnly": "del-cli dist && cross-env BABEL_ENV=publish babel src --out-dir dist --ignore /__tests__/",
"test": "nyc ava src/__tests__"
"pretest": "xo src tests",
"prepublishOnly": "del-cli dist && cross-env BABEL_ENV=publish babel src --out-dir dist",
"test": "nyc ava"
},

@@ -32,26 +32,32 @@ "files": [

"plugin-error": "^1.0.1",
"svgo": "^1.3.2"
"svgo": "^2.3.1"
},
"devDependencies": {
"ava": "^0.17.0",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.3",
"babel-preset-env": "^1.7.0",
"babel-register": "^6.26.0",
"chai": "^4.2.0",
"@babel/cli": "^7.14.5",
"@babel/core": "^7.14.6",
"@babel/preset-env": "^7.14.7",
"@babel/register": "^7.14.5",
"ava": "^3.15.0",
"coveralls": "^3.1.0",
"cross-env": "^7.0.2",
"del-cli": "^3.0.1",
"eslint": "^3.0.0",
"eslint-config-cssnano": "^3.1.3",
"eslint-plugin-babel": "^3.3.0",
"eslint-plugin-import": "^2.21.2",
"cross-env": "^7.0.3",
"del-cli": "^4.0.0",
"lodash.clonedeep": "^4.5.0",
"nyc": "^15.1.0",
"vinyl": "^2.2.0"
"prettier": "^2.3.2",
"vinyl": "^2.2.1",
"xo": "^0.38.2"
},
"eslintConfig": {
"extends": "cssnano"
"prettier": {
"bracketSpacing": false,
"trailingComma": "es5",
"tabWidth": 4,
"semi": true,
"singleQuote": true
},
"xo": {
"prettier": true
},
"ava": {
"require": "babel-register"
"require": "@babel/register",
"verbose": true
},

@@ -61,5 +67,13 @@ "nyc": {

"node_modules",
"**/__tests__"
"tests"
],
"check-coverage": true,
"functions": 100,
"lines": 100,
"branches": 100,
"reporter": [
"text",
"html"
]
}
}

@@ -1,12 +0,15 @@

# [gulp][gulp]-svgmin [![Build Status](https://travis-ci.org/ben-eb/gulp-svgmin.svg?branch=master)][ci] [![NPM version](https://badge.fury.io/js/gulp-svgmin.svg)][npm] [![Dependency Status](https://gemnasium.com/ben-eb/gulp-svgmin.svg)][deps]
# gulp-svgmin
> Minify SVG with [SVGO][orig].
[![Build Status](https://travis-ci.org/ben-eb/gulp-svgmin.svg?branch=master)][travis-status]
[![NPM version](https://badge.fury.io/js/gulp-svgmin.svg)][npm-status]
[![Dependency Status](https://david-dm.org/ben-eb/gulp-svgmin.svg)][deps-status]
*If you have any difficulties with the output of this plugin, please use the
[SVGO tracker][bugs].*
> A [Gulp][gulp-url] plugin to minify SVG files with [svgo-url].
*If you have any difficulties with the output of this plugin, please use the [SVGO tracker][svgo-bugs].*
## Install
With [npm](https://npmjs.org/package/gulp-svgmin) do:
With [npm][npm-url] do:

@@ -17,68 +20,100 @@ ```

## Example
```js
var gulp = require('gulp');
var svgmin = require('gulp-svgmin');
import { src, dest } from 'gulp';
import svgmin from 'gulp-svgmin';
gulp.task('default', function () {
return gulp.src('logo.svg')
.pipe(svgmin())
.pipe(gulp.dest('./out'));
});
const defaultTask = () =>
src('logo.svg')
.pipe(svgmin())
.pipe(dest('./out'));
export default defaultTask;
```
## Configuration file
## Plugins
By default, `gulp-svgmin` loads options from a `svgo.config.js` file in your project. See the [svgo’s configuration docs][svgo-config] for more info on how to write one.
Optionally, you can customise the output by specifying the `plugins` option. You
will need to provide the config in comma separated objects, like the example
below. Note that you can either disable the plugin by setting it to false,
or pass different options to change the default behaviour.
You can control which directory `svgo` searches for `svgo.config.js` with the `cwd` option. Or you can use a different file name with the `configFile` option.
```js
gulp.task('default', function () {
return gulp.src('logo.svg')
.pipe(svgmin({
plugins: [{
removeDoctype: false
}, {
removeComments: false
}, {
cleanupNumericValues: {
floatPrecision: 2
}
}, {
convertColors: {
names2hex: false,
rgb2hex: false
}
}]
}))
.pipe(gulp.dest('./out'));
});
import { src, dest } from 'gulp';
import svgmin from 'gulp-svgmin';
const defaultTask = () =>
src('logo.svg')
.pipe(svgmin({
// Specify an absolute directory path to
// search for the config file.
cwd: '/users/admin/project/assets',
// This path is relative to process.cwd()
// or the 'cwd' option.
configFile: 'images/svg/config.js',
}))
.pipe(dest('./out'));
export default defaultTask;
```
You can view the [full list of plugins here][plugins].
## Options
Instead of using a config file, you can pass an object of svgo’s options to the `gulp-svgmin` plugin. You will need to provide the config in comma separated objects, like the example below.
## Beautify
```js
const defaultTask = () =>
src('logo.svg')
.pipe(svgmin({
// Ensures the best optimization.
multipass: true,
js2svg: {
// Beutifies the SVG output instead of
// stripping all white space.
pretty: true,
indent: 2,
},
// Alter the default list of plugins.
plugins: [
// You can enable a plugin with just its name.
'sortAttrs',
{
name: 'removeViewBox',
// Disable a plugin by setting active to false.
active: false,
},
{
name: 'cleanupIDs',
// Add plugin options.
params: {
minify: true,
}
},
],
}))
.pipe(dest('./out'));
```
You can also use `gulp-svgmin` to optimise your SVG but render a pretty output,
instead of the default where all extraneous whitespace is removed:
You can view the [full list of plugins here][svgo-plugins].
By default, the plugins list given to the gulp plugin will alter the default list of svgo plugins. Optionally, you can specify your plugins and set the `full` flag to `true` to indicate that your plugins list should not be merged with the default list of plugins.
```js
gulp.task('pretty', function () {
return gulp.src('logo.svg')
.pipe(svgmin({
js2svg: {
pretty: true
}
}))
.pipe(gulp.dest('./out'))
});
const defaultTask = () =>
src('logo.svg')
.pipe(svgmin({
multipass: true,
// The plugins list is the full list of plugins
// to use. The default list is ignored.
full: true,
plugins: [
'removeDoctype',
'removeComments',
'sortAttrs',
// ...
],
}))
.pipe(dest('./out'));
```
## Per-file options

@@ -88,41 +123,46 @@

returns `svgo` options. For example, if you need to prefix ids with filenames
to make them unique before combining svgs with [gulp-svgstore](https://github.com/w0rm/gulp-svgstore):
to make them unique before combining svgs with [gulp-svgstore][gulp-svgostore]:
```js
gulp.task('default', function () {
return gulp.src('src/*.svg')
.pipe(svgmin(function getOptions (file) {
var prefix = path.basename(file.relative, path.extname(file.relative));
return {
plugins: [{
cleanupIDs: {
prefix: prefix + '-',
minify: true
}
}]
}
}))
.pipe(svgstore())
.pipe(gulp.dest('./dest'));
});
const defaultTask = () =>
src('src/*.svg')
.pipe(svgmin(function getOptions(file) {
const prefix = path.basename(
file.relative,
path.extname(file.relative)
);
return {
plugins: [
{
name: 'cleanupIDs',
parmas: {
prefix: prefix + '-',
minify: true,
},
},
],
};
}))
.pipe(svgstore())
.pipe(dest('./dest'));
```
## Contributing
Pull requests are welcome. If you add functionality, then please add unit tests
to cover it.
Pull requests are welcome. If you add functionality, then please add unit tests to cover it.
## License
MIT © [Ben Briggs](http://beneb.info)
MIT © [Ben Briggs](https://beneb.info)
[bugs]: https://github.com/svg/svgo/issues
[ci]: https://travis-ci.org/ben-eb/gulp-svgmin
[deps]: https://gemnasium.com/ben-eb/gulp-svgmin
[gulp]: https://github.com/wearefractal/gulp
[npm]: http://badge.fury.io/js/gulp-svgmin
[orig]: https://github.com/svg/svgo
[plugins]: https://github.com/svg/svgo/tree/master/plugins
[travis-status]: https://travis-ci.org/ben-eb/gulp-svgmin
[deps-status]: https://david-dm.org/ben-eb/gulp-svgmin
[npm-status]: https://badge.fury.io/js/gulp-svgmin
[npm-url]: https://npmjs.org/package/gulp-svgmin
[gulp-url]: https://github.com/gulpjs/gulp
[gulp-svgostore]: https://github.com/w0rm/gulp-svgstore
[svgo-url]: https://github.com/svg/svgo
[svgo-bugs]: https://github.com/svg/svgo/issues
[svgo-config]: https://github.com/svg/svgo#configuration
[svgo-plugins]: https://github.com/svg/svgo#built-in-plugins

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc