[英]Using npm how can I download a package as a zip with all of its dependencies included in the package
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.我想要做的是下载包含所有依赖项的包,以便将它们传输到另一台没有互联网连接的计算机并安装在那里。
So the scenario would be:所以场景是:
Download package (to zip/tarball/whatever file) without installing it.下载包(压缩/压缩包/任何文件)而不安装它。
Included in that downloaded file would be all of its dependencies (correct versions, and it's dependencies' dependencies).下载的文件中将包含它的所有依赖项(正确的版本,以及它的依赖项的依赖项)。
Transfer file to other computer.将文件传输到其他计算机。
Run npm install
to file location (optional -g
important).运行
npm install
到文件位置(可选-g
重要)。
Package is installed with dependencies.软件包与依赖项一起安装。
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.这是我第一次使用 node,所以我担心我没有正确研究它,因为缺乏对 node/npm 术语的了解。
Download the package to a machine with internet. 将包下载到具有互联网的计算机。
Make sure your app package has a package.json
file at its root with all of your dependencies listed in it. 确保您的应用包在其根目录下有一个
package.json
文件,其中列出了所有依赖项。 You can make npm save your dependencies in package.json
by doing npm install dependency-name --save
. 你可以让故宫保存的依赖关系
package.json
做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. --save
标志将导致npm将依赖项写入应用程序的package.json
文件(如果有)。 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. 如果您需要通过在应用程序目录中运行
npm init
,您还可以指示npm为您的应用程序创建package.json
文件。
Run npm install
from inside the app's directory. 从应用程序目录中运行
npm install
。 This will create the node_modules
directory and install all the dependencies listed in the app's package.json
file. 这将创建
node_modules
目录并安装应用程序的package.json
文件中列出的所有依赖项。
Zip up the directory now that it has a node_modules
directory in it with all your dependencies installed. 现在压缩目录,其中包含一个
node_modules
目录,其中安装了所有依赖项。 Transfer the zip archive to another machine. 将zip存档转移到另一台计算机。
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.
该应用程序现在需要它,并且已经安装了依赖项。
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. 现在只需使用
node app.js
运行应用程序,将“app.js”替换为应用程序主入口点文件的名称。
Simply run npm install
in the package directory and archive the entirety of it. 只需在包目录中运行
npm install
并将其全部存档。 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. 假设没有非npm要求你需要肉,两台机器都运行相同版本的节点,不需要做任何事情。 All of the downloaded dependencies will be installed inside the
./node_modules
. 所有下载的依赖项都将安装在
./node_modules
。 But it is a generally good idea to archive the entire package, as the developer might have implemented some additional setup routines. 但是归档整个包通常是个好主意,因为开发人员可能已经实现了一些额外的设置例程。
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. 基本上脚本的作用是重写一个模块的
package.json
文件,将其所有dependencies
移动到bundleDependencies
,然后打包整个东西。 Upload the resulting tarball to your server, then npm install
it. 将生成的tarball上传到您的服务器,然后
npm install
它。 Works a treat. 工作一种享受。
you can download package with all its dependencies with its dependents using single command.您可以使用单个命令下载包及其所有依赖项及其依赖项。 Kindly refer this link npm-package-downloader
请参考此链接npm-package-downloader
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.