使用 npm 通过 http 下载 zip 文件

download a zip file via http with npm

在某个http:// | 有一个zip 文件https:// 位置.

在这种情况下,它是资产的 zip,特别是字体,因此它不是 js 包,也没有 git 存储库或其他类型的存储库。

使用 bower 可以只引用位置,它会下载并解压缩 zip 文件。

如何使用 npm 实现此目的?最好不要 hack,因为我的 postinstall 脚本已经做了很多事情。

在文件 package.json 中添加:

  "scripts": {
    "postinstall": "node download.js && <whatever you had here before>"
  },
  "dependencies": {
    "download-file": "0.1.5"
  }

然后将此添加到文件 download.js 旁边的文件 package.json:

var download = require('download-file')
const url = "https://YourFileLocation";
const options = {directory: "YourDirName", filename: "YourFileName"};
console.log("Installing " + options.directory + "/" + options.filename);
download(url, options, function(error) {if (error) throw error;});

参见:https://www.npmjs.com/package/download-file