简体   繁体   English

使用全局包打包nodejs应用程序

[英]Package nodejs application with global packages

We have a project which have to be packaged as a zip so we can distribute it to our cliens. 我们有一个必须打包成拉链的项目,所以我们可以将它分发给我们的cliens。 With the normal node_modules directory i have no problems. 使用正常的node_modules目录我没有问题。 I just put the directory and the node.exe together in my project folder and can start our project on every other computer without installing node or running any npm command. 我只是将目录和node.exe放在我的项目文件夹中,并且可以在所有其他计算机上启动我们的项目而无需安装节点或运行任何npm命令。

But now i have a dependecy on phantomjs which needs to be installed as a global package npm install -g phantomjs . 但是现在我对phantomjs有所依赖,需要安装为全局包npm install -g phantomjs

How do i pack modules like this into our project? 我如何将这样的模块打包到我们的项目中? I first thought of copying phantomjs into the local node_modules directory and set the path variable NODE_PATH to this directory. 我首先想到将phantomjs复制到本地node_modules目录并将路径变量NODE_PATH设置为此目录。 It doesn't find phantomjs. 它找不到幻影。

Development and client platforms are both windows. 开发和客户端平台都是窗口。

Well, generally it is fine to install global dependencies with the --save flag and call their bins like ./node_modules/phantomjs/bin/phantomjs /*now executes*/ (just as an illustrative example). 好吧,通常可以使用--save标志安装全局依赖项并调用它们的bin,如./node_modules/phantomjs/bin/phantomjs /*now executes*/ (仅作为说明性示例)。

However, with with Phantom it's not that simple, since it's downloading binaries and/or even compiling. 然而,与Phantom一起使用它并不那么简单,因为它正在下载二进制文件和/或甚至编译。 You would have three options: 你有三个选择:

  1. ssh into target and just npm install -g phantomjs before or define it in a manifest eg Dockerfile just like that, if you are using containers. ssh到目标并且只是npm install -g phantomjs之前或者在清单中定义它,例如Dockerfile就像那样,如果你正在使用容器。
  2. Compile it from source as advised here . 根据此处的建议从源代码编译它。
  3. If you are using the CLI, then just the --save approach. 如果您使用的是CLI,那么只需使用--save方法。

So I hardly advise just making a Docker image out of it and ship it as tarball. 所以我几乎不建议只用它来制作一个Docker镜像并将其作为tarball发送。 You can't zip the platform dependent Phantom installation, unfortunately. 不幸的是,您不能压缩平台相关的Phantom安装。

Also lots of dependencies like karma-runner-phantomjs look for the path of the global dependencies to resolve it for their use. 此外,许多依赖项(如karma-runner-phantomjs查找全局依赖项的路径以解决它们的使用问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM