配置.npmrc
在项目根目录下创建.npmrc文件,文件内容如下:
registry = https://registry.npmmirror.com/
sharp_binary_host=https://npmmirror.com/mirrors/sharp
sharp_libvips_binary_host=https://npmmirror.com/mirrors/sharp-libvips
electron_mirror=https://registry.npmmirror.com/-/binary/electron/
electron-builder-binaries_mirror=https://registry.npmmirror.com/-/binary/electron-builder-binaries/
npm提供了.npmrc配置文件并注入到进程的env环境变量中,从上面的源码可知,node-pre-gyp会优先读取npm_config_{包名}_binary_host_mirror(.npmrc中的变量均会被npm添加npm_config_前缀, 所以我们配置时无需添加npm_config_前缀)
原理参考: