开发者

Using compiled node dependencies on different environments

I have a node project that I run locally and deploy to a CentOS server. I have a few dependencies, one of which relies on a compiled dependency.

Using npm, I can compile the dependency locally using npm install, and it'll work great. This however is not compiled for the deployment server, so it will break if it is uploaded.

I can compile the dependency on a CentOS box, and it'll work on the server, but it'll break in the local environment.

Can anyone think of a workaround so that I can force node to use the global dependencies in the local environment, and a the local ones on the server?

Thanks!


Update:

I've figured out a way to do this for now, it's not elegant, but it works:

    开发者_StackOverflow中文版
  1. run npm install on my local environment
  2. rename the node_modules folder to node_modules_local
  3. run npm install on the server
  4. prepend a variable to all require() paths
  5. set a local environment variable to "development"
  6. check if we're in development mode, if we are, set the require path variable to ./node_modules_local.


Check in the source code of the dependencies (compiled dependencies and js-only-dependencies). When you deploy your app run 'npm rebuild' on the server. Seems like this is the officially recommended way to go. See http://www.mikealrogers.com/posts/nodemodules-in-git.html for details

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜