Skip to content

Commit

Permalink
Meta tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Nov 6, 2018
1 parent b57f1d6 commit 4fd98eb
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 25 deletions.
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
* text=auto
*.js text eol=lf
* text=auto eol=lf
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
sudo: false
language: node_js
node_js:
- "10"
- "8"
- "6"
- '10'
- '8'
- '6'
16 changes: 8 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ const getDefaultPlugins = () =>
return plugins.concat(instance);
}, []);

module.exports = (plugins, opts) => {
module.exports = (plugins, options) => {
if (typeof plugins === 'object' && !Array.isArray(plugins)) {
opts = plugins;
options = plugins;
plugins = null;
}

opts = Object.assign({
// TODO: remove this when gulp get's a real logger with levels
options = Object.assign({
// TODO: Remove this when Gulp gets a real logger with levels
verbose: process.argv.includes('--verbose')
}, opts);
}, options);

const validExts = ['.jpg', '.jpeg', '.png', '.gif', '.svg'];

Expand All @@ -62,7 +62,7 @@ module.exports = (plugins, opts) => {
}

if (!validExts.includes(path.extname(file.path).toLowerCase())) {
if (opts.verbose) {
if (options.verbose) {
log(`${PLUGIN_NAME}: Skipping unsupported image ${chalk.blue(file.relative)}`);
}

Expand All @@ -87,15 +87,15 @@ module.exports = (plugins, opts) => {
totalFiles++;
}

if (opts.verbose) {
if (options.verbose) {
log(`${PLUGIN_NAME}:`, chalk.green('✔ ') + file.relative + chalk.gray(` (${msg})`));
}

file.contents = data;
cb(null, file);
})
.catch(error => {
// TODO: remove this setImmediate when gulp 4 is targeted
// TODO: Remove this setImmediate when Gulp 4 is targeted
setImmediate(cb, new PluginError(PLUGIN_NAME, error, {fileName: file.path}));
});
}, cb => {
Expand Down
32 changes: 21 additions & 11 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# gulp-imagemin [![Build Status](https://travis-ci.org/sindresorhus/gulp-imagemin.svg?branch=master)](https://travis-ci.org/sindresorhus/gulp-imagemin) [![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/xojs/xo)
# gulp-imagemin [![Build Status](https://travis-ci.com/sindresorhus/gulp-imagemin.svg?branch=master)](https://travis-ci.com/sindresorhus/gulp-imagemin) [![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/xojs/xo)

> Minify PNG, JPEG, GIF and SVG images with [imagemin](https://github.com/imagemin/imagemin)
> Minify PNG, JPEG, GIF and SVG images with [`imagemin`](https://github.com/imagemin/imagemin)
*Issues with the output should be reported on the imagemin [issue tracker](https://github.com/imagemin/imagemin/issues).*
*Issues with the output should be reported on the [`imagemin` issue tracker](https://github.com/imagemin/imagemin/issues).*

---

Expand Down Expand Up @@ -36,7 +36,7 @@ gulp.task('default', () =>
### Custom plugin options

```js
//
.pipe(imagemin([
imagemin.gifsicle({interlaced: true}),
imagemin.jpegtran({progressive: true}),
Expand All @@ -48,32 +48,42 @@ gulp.task('default', () =>
]
})
]))
//
```

Note that you may come across an older, implicit syntax. In versions < 3, the same was written like this:

```js
//
.pipe(imagemin({
interlaced: true,
progressive: true,
optimizationLevel: 5,
svgoPlugins: [{removeViewBox: true}]
svgoPlugins: [
{
removeViewBox: true
}
]
}))
//
```

### Custom plugin options and custom `gulp-imagemin` options

```js
//
.pipe(imagemin([
imagemin.svgo({plugins: [{removeViewBox: true}]})
imagemin.svgo({
plugins: [
{
removeViewBox: true
}
]
})
], {
verbose: true
}))
//
```


Expand Down

0 comments on commit 4fd98eb

Please sign in to comment.