[英]Is it possible to have a separate node_modules folder for devDependencies?
I've got a Node app that I'm deploying to Heroku. 我有一个我正在部署到Heroku的Node应用程序。 Their docs say it's best practice to check in your
node_modules
directory (ie don't gitignore it), for faster deploys and for dev/prod parity. 他们的文档说最好检查你的
node_modules
目录 (即不要 gitignore),以便更快地部署和开发/生产奇偶校验。
In my package.json
, I've got loads of devDependencies
(mostly Grunt plugins and all their deps) and a few regular production dependencies
like Express. 在我的
package.json
,我有大量的devDependencies
(主要是Grunt插件及其所有deps)和一些常规生产dependencies
如Express。 Heroku only needs the production deps. Heroku只需要生产代表。 I'd rather not check in all my dev deps, because they come to about 50MB.
我宁愿不检查所有的开发设备,因为它们大约50MB。
Is there some way to have a separate folder for you dev deps, eg node_modules_dev
? 有没有办法为你开发一个单独的文件夹,例如
node_modules_dev
? If this was possible, then I could just add node_modules_dev
to my .gitignore
, and check in the regular production node_modules
directory as per Heroku's advice. 如果这是可能的,那么我可以将
node_modules_dev
添加到我的.gitignore
,并根据Heroku的建议检查常规生产node_modules
目录。
Is there any way to do this? 有没有办法做到这一点? Or can you think of another way to do what I'm trying to do?
或者你能想到另一种方法去做我想做的事吗?
I use a CI server to build, test, and deploy my files — so I was looking for a similar solution that would prevent me from needing to deploy extra dependencies and/or re-build on Heroku. 我使用CI服务器来构建,测试和部署我的文件 - 所以我正在寻找一种类似的解决方案,这将阻止我需要部署额外的依赖项和/或重新构建Heroku。
After all my tests run, I run npm prune --production , which removes devDependencies
from node_modules
, and then I push the result to Heroku. 我所有的测试运行后,我跑NPM修剪-生产 ,从而消除
devDependencies
从node_modules
,然后我推结果的Heroku。
No extra files go to the server, and deployment times are much faster since Heroku avoids having to build all the binaries usually found in Gulp/Grunt plugins. 没有额外的文件进入服务器,并且部署时间要快得多,因为Heroku避免了必须构建通常在Gulp / Grunt插件中找到的所有二进制文件。
If you don't mind checking them in anyways, and your only concern is the resulting slug size (ie: not your git repo size, or transfer of that repo to Heroku), then simply add the relevant node_modules to .slugignore
. 如果您不介意检查它们,并且您唯一关心的是产生的slug大小(即:不是您的git repo大小,或者将该repo转移到Heroku),那么只需将相关的node_modules添加到
.slugignore
。
Docs: Ignoring files with .slugignore . 文档: 使用.slugignore忽略文件 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.