imagemin / cwebp-bin

cwebp bin-wrapper that makes it seamlessly available as a local dependency
https://developers.google.com/speed/webp
MIT License
91 stars 36 forks source link

Please add environment variable to set bin download URL #34

Open peixin opened 4 years ago

peixin commented 4 years ago

like node-sass can set sass-binary-site to download bin library.

function getBinaryUrl() {
  var site = getArgument('--sass-binary-site') ||
             process.env.SASS_BINARY_SITE  ||
             process.env.npm_config_sass_binary_site ||
             (pkg.nodeSassConfig && pkg.nodeSassConfig.binarySite) ||
             'https://github.com/sass/node-sass/releases/download';

  return [site, 'v' + pkg.version, getBinaryName()].join('/');
}

For some reason in china download from github is very slow.

We usually install package from https://npm.taobao.org/mirrors

pngquant-bin: https://npm.taobao.org/mirrors/pngquant-bin/ mozjpeg-bin: https://npm.taobao.org/mirrors/mozjpeg-bin/ cwebp-bin: https://npm.taobao.org/mirrors/cwebp-bin/

Jamuz commented 4 years ago

Edit: There seems to be a related PR already for this in bin-wrapper project: https://github.com/kevva/bin-wrapper/pull/73.

Environment variable for custom cwebp binary download URL would be great!

In our CI environment we do not have access to the internet, but we need to rely on our internal Artifactory contents instead. The Artifactory instance is proxying raw.githubusercontent.com, so we do have access to the binaries available in https://raw.githubusercontent.com/imagemin/cwebp-bin/v${pkg.version}/vendor/ (mentioned in cwebp-bin/lib/index.js), but at a different URL. The problem is that we cannot override the URL used in cwebp-bin/lib/index.js, so npm install fails in our CI.

As a workaround I tried to download the binary to node_modules/cwebp-bin/vendor/ directory before running npm install, but it seems that the whole node_modules/cwebp-bin directory gets removed and re-created during npm install so my downloaded cwebp binary is gone before postinstall actions.

Is there any workaround to make this working with the environment I'm working in - I can download manually all required components, but npm install fails with our current settings. Any pre-tasks I could do prior to npm install to make it pass? (I can use yum to install webp) Is it possible to somehow disable the removal of pre-downloaded vendor/cwebp when issuing npm install?

FYI: The dependency to cwebp-bin comes from

my-project@1.0.0
├─┬ image-webpack-loader@4.6.0
│ ├─┬ imagemin-webp@5.1.0
│ │ ├─┬ cwebp-bin@5.1.0
mafrosis commented 4 years ago

Another corporate user here looking for the same answer. An environment variable to specify the base URL is the common way to fix this.