Skip to content

Commit 696b6ac

Browse files
zceisindresorhus
authored andcommitted
Pass options to exposed plugins (#231)
1 parent ccee73a commit 696b6ac

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

index.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,20 @@ const plur = require('plur');
99

1010
const defaultPlugins = ['gifsicle', 'jpegtran', 'optipng', 'svgo'];
1111

12-
const loadPlugin = plugin => {
12+
const loadPlugin = (plugin, args) => {
1313
try {
14-
return require(`imagemin-${plugin}`)(); // eslint-disable-line import/no-dynamic-require
14+
return require(`imagemin-${plugin}`).apply(null, args); // eslint-disable-line import/no-dynamic-require
1515
} catch (err) {
1616
gutil.log(`gulp-imagemin: Couldn't load default plugin "${plugin}"`);
1717
}
1818
};
1919

20+
const exposePlugin = plugin =>
21+
function () {
22+
const args = [].slice.call(arguments);
23+
return loadPlugin(plugin, args);
24+
};
25+
2026
const getDefaultPlugins = () =>
2127
defaultPlugins.reduce((plugins, plugin) => {
2228
const instance = loadPlugin(plugin);
@@ -104,7 +110,7 @@ module.exports = (plugins, opts) => {
104110
});
105111
};
106112

107-
module.exports.gifsicle = () => loadPlugin('gifsicle');
108-
module.exports.jpegtran = () => loadPlugin('jpegtran');
109-
module.exports.optipng = () => loadPlugin('optipng');
110-
module.exports.svgo = () => loadPlugin('svgo');
113+
module.exports.gifsicle = exposePlugin('gifsicle');
114+
module.exports.jpegtran = exposePlugin('jpegtran');
115+
module.exports.optipng = exposePlugin('optipng');
116+
module.exports.svgo = exposePlugin('svgo');

0 commit comments

Comments
 (0)