使用npm如何下载包作为zip包,其中包含所有依赖项

时间:2022-09-09 23:00:26

What I'm trying to do is download packages with all their dependencies, in order to transfer them to another computer that does not have an internet connection and install it there.

我要做的是下载包含所有依赖项的包,以便将它们传输到另一台没有Internet连接的计算机并在那里安装它。

So the scenario would be:

所以场景将是:

  1. Download package (to zip/tarball/whatever file) without installing it.

    下载包(到zip / tarball /任何文件)而不安装它。

  2. Included in that downloaded file would be all of its dependencies (correct versions, and it's dependencies' dependencies).

    包含在下载的文件中的将是它的所有依赖项(正确的版本,以及它的依赖项的依赖项)。

  3. Transfer file to other computer.

    将文件传输到其他计算机。

  4. Run npm install to file location (optional -g important).

    将npm install运行到文件位置(可选-g important)。

  5. Package is installed with dependencies.

    包安装有依赖项。

  6. Happy camper.

    快乐的露营者。

I feel like there has to be a npm command to download and pack (create) files this way.

我觉得必须有一个npm命令以这种方式下载和打包(创建)文件。

I've tried looking for a solution for this to no avail.

我试过寻找一个解决方案无济于事。

This is my first time using node so I'm affraid I'm not researching it correctly because lack of knowledge of the node/npm lingo.

这是我第一次使用节点,所以我很害怕我没有正确研究它,因为缺乏节点/ npm术语的知识。

3 个解决方案

#1


1  

I just used this gist by Jack Gill to do exactly what you describe -- bundle up a package, with all its dependencies. Basically what the script does is re-write a module's package.json file to move all its dependencies to bundleDependencies, then pack the whole thing. Upload the resulting tarball to your server, then npm install it. Works a treat.

我只是用杰克吉尔的这个要点来完成你所描述的内容 - 捆绑一个包及其所有依赖项。基本上脚本的作用是重写一个模块的package.json文件,将其所有依赖项移动到bundleDependencies,然后打包整个东西。将生成的tarball上传到您的服务器,然后npm安装它。工作一种享受。

#2


1  

Simply run npm install in the package directory and archive the entirety of it. Assuming there are no non-npm requirements you need to meat and both machines are running the same version of node, nothing more needs to be done. All of the downloaded dependencies will be installed inside the ./node_modules. But it is a generally good idea to archive the entire package, as the developer might have implemented some additional setup routines.

只需在包目录中运行npm install并将其全部存档。假设没有非npm要求你需要使用并且两台机器都运行相同版本的节点,则不需要做任何其他事情。所有下载的依赖项都将安装在./node_modules中。但是归档整个软件包通常是个好主意,因为开发人员可能已经实现了一些额外的设置例程。

#3


1  

  1. Download the package to a machine with internet.

    将软件包下载到具有Internet的计算机上。

  2. Make sure your app package has a package.json file at its root with all of your dependencies listed in it. You can make npm save your dependencies in package.json by doing npm install dependency-name --save. The --save flag will cause npm to write the dependency to your app's package.json file if it has one. If it doesn't have on then it will do nothing. You can also instruct npm to create a package.json file for your app if you need to by simply running npm init from in your app's directory.

    确保您的应用包在其根目录下有一个package.json文件,其中列出了所有依赖项。您可以通过执行npm install dependency-name --save使npm在config.json中保存依赖项。 --save标志将导致npm将依赖项写入应用程序的package.json文件(如果有)。如果它没有,那么它什么都不做。如果您需要通过在应用程序目录中运行npm init,您还可以指示npm为您的应用程序创建package.json文件。

  3. Run npm install from inside the app's directory. This will create the node_modules directory and install all the dependencies listed in the app's package.json file.

    从应用程序目录中运行npm install。这将创建node_modules目录并安装应用程序的package.json文件中列出的所有依赖项。

  4. Zip up the directory now that it has a node_modules directory in it with all your dependencies installed. Transfer the zip archive to another machine.

    现在压缩目录,其中包含一个node_modules目录,并且安装了所有依赖项。将zip存档转移到另一台计算机。

  5. Simply unpack the archive in its final destination and you're done. The app is now where it needs to be and the dependencies are already installed.

    只需将存档打包到最终目的地即可完成。该应用程序现在需要它,并且已经安装了依赖项。

  6. Now just run the application with node app.js, replacing "app.js" with whatever the name of the app's main entry point file is.

    现在只需使用节点app.js运行应用程序,将“app.js”替换为应用程序主入口点文件的名称。

#1


1  

I just used this gist by Jack Gill to do exactly what you describe -- bundle up a package, with all its dependencies. Basically what the script does is re-write a module's package.json file to move all its dependencies to bundleDependencies, then pack the whole thing. Upload the resulting tarball to your server, then npm install it. Works a treat.

我只是用杰克吉尔的这个要点来完成你所描述的内容 - 捆绑一个包及其所有依赖项。基本上脚本的作用是重写一个模块的package.json文件,将其所有依赖项移动到bundleDependencies,然后打包整个东西。将生成的tarball上传到您的服务器,然后npm安装它。工作一种享受。

#2


1  

Simply run npm install in the package directory and archive the entirety of it. Assuming there are no non-npm requirements you need to meat and both machines are running the same version of node, nothing more needs to be done. All of the downloaded dependencies will be installed inside the ./node_modules. But it is a generally good idea to archive the entire package, as the developer might have implemented some additional setup routines.

只需在包目录中运行npm install并将其全部存档。假设没有非npm要求你需要使用并且两台机器都运行相同版本的节点,则不需要做任何其他事情。所有下载的依赖项都将安装在./node_modules中。但是归档整个软件包通常是个好主意,因为开发人员可能已经实现了一些额外的设置例程。

#3


1  

  1. Download the package to a machine with internet.

    将软件包下载到具有Internet的计算机上。

  2. Make sure your app package has a package.json file at its root with all of your dependencies listed in it. You can make npm save your dependencies in package.json by doing npm install dependency-name --save. The --save flag will cause npm to write the dependency to your app's package.json file if it has one. If it doesn't have on then it will do nothing. You can also instruct npm to create a package.json file for your app if you need to by simply running npm init from in your app's directory.

    确保您的应用包在其根目录下有一个package.json文件,其中列出了所有依赖项。您可以通过执行npm install dependency-name --save使npm在config.json中保存依赖项。 --save标志将导致npm将依赖项写入应用程序的package.json文件(如果有)。如果它没有,那么它什么都不做。如果您需要通过在应用程序目录中运行npm init,您还可以指示npm为您的应用程序创建package.json文件。

  3. Run npm install from inside the app's directory. This will create the node_modules directory and install all the dependencies listed in the app's package.json file.

    从应用程序目录中运行npm install。这将创建node_modules目录并安装应用程序的package.json文件中列出的所有依赖项。

  4. Zip up the directory now that it has a node_modules directory in it with all your dependencies installed. Transfer the zip archive to another machine.

    现在压缩目录,其中包含一个node_modules目录,并且安装了所有依赖项。将zip存档转移到另一台计算机。

  5. Simply unpack the archive in its final destination and you're done. The app is now where it needs to be and the dependencies are already installed.

    只需将存档打包到最终目的地即可完成。该应用程序现在需要它,并且已经安装了依赖项。

  6. Now just run the application with node app.js, replacing "app.js" with whatever the name of the app's main entry point file is.

    现在只需使用节点app.js运行应用程序,将“app.js”替换为应用程序主入口点文件的名称。