From 6131a57e02a6cb752a96c0f12bb154983bd373b2 Mon Sep 17 00:00:00 2001 From: leo108 Date: Sun, 12 Aug 2018 16:44:21 +0800 Subject: [PATCH] Add support for custom setting binary site Developers in China have trouble to download binary files from Github directly, this PR supports for setting custom binary site by `MOZJPEG_BINARY_SITE=https://npm.taobao.org/mirrors/optipng-bin/ yarn` which will save our lives. Thanks to [node-sass](https://github.com/sass/node-sass/blob/master/lib/extensions.js#L240) project which inspires me. --- lib/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index a8d3ee5..d1b4541 100644 --- a/lib/index.js +++ b/lib/index.js @@ -3,7 +3,10 @@ const path = require('path'); const BinWrapper = require('bin-wrapper'); const pkg = require('../package.json'); -const url = `https://raw.githubusercontent.com/imagemin/optipng-bin/v${pkg.version}/vendor/`; +const binary_site = process.env.OPTIPNG_BINARY_SITE || + process.env.npm_config_optipng_binary_site || + 'https://raw.githubusercontent.com/imagemin/optipng-bin'; +const url = `${binary_site}/v${pkg.version}/vendor/`; module.exports = new BinWrapper() .src(`${url}macos/optipng`, 'darwin')