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中文版
- run npm install on my local environment
- rename the node_modules folder to node_modules_local
- run npm install on the server
- prepend a variable to all
require()
paths - set a local environment variable to "development"
- 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
精彩评论