简体   繁体   English

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

[英]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:所以场景是:

  1. Download package (to zip/tarball/whatever file) without installing it.下载包(压缩/压缩包/任何文件)而不安装它。

  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重要)。

  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.这是我第一次使用 node,所以我担心我没有正确研究它,因为缺乏对 node/npm 术语的了解。

  1. Download the package to a machine with internet. 将包下载到具有互联网的计算机。

  2. 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.jsonnpm 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文件。

  3. 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文件中列出的所有依赖项。

  4. 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存档转移到另一台计算机。

  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. 现在只需使用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.

相关问题 如何创建包含软件包及其依赖项的NPM存储库 - How can I create an NPM repository containing a package and its dependencies 如何以 zip 格式下载发布到 GitHub 包注册表的 NPM 包? - How to download NPM package published to GitHub packages registry as a zip? 将npm install用于本地软件包时,将包括所有文件 - When using npm install for local package, all files are included 如何将我通过npm安装的所有依赖项保存到我的package.json文件中? - How do I save all the dependencies I install through npm into my package.json file? npm:如何从 package.json 全局安装所有依赖项? - npm: How to install all dependencies from package.json globally? 我可以在npm package.json中指定可选的模块依赖项吗? - Can I specify optional module dependencies in npm package.json? Webpack不会加载/解析git包含的npm软件包的依赖项 - Webpack does not load/resolve dependencies of npm package included through git 如何找到由NPM软件包的某个依赖项安装的二进制文件,以便可以执行它? - How do I locate a binary installed by one of my NPM package's dependencies so I can execute it? Grunt和NPM,打包所有生产依赖项 - Grunt and NPM, package all production dependencies 预先构建的NPM软件包:如何使用户摆脱依赖关系? - Pre-built NPM package: How can I spare users my dependencies?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM