简体   繁体   English

是否可以为devDependencies设置单独的node_modules文件夹?

[英]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修剪-生产 ,从而消除devDependenciesnode_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.

相关问题 将node_modules文件夹放置在单独的文件夹中 - place node_modules folder in separate folder 已安装 npm 包,用于 node_modules 目录中存在的依赖项和 devDependencies - Are installed npm packages for dependencies and devDependencies present in node_modules dir 另一个文件夹中的 Node_modules - Node_modules in another folder 恢复 node_modules 文件夹 - Restore node_modules folder 是否可以在项目之间共享 node_modules 目录 - Is it possible to have a node_modules directory shared between projects 将 node_modules 文件夹用于自定义模块 - Using node_modules folder for custom modules node_modules文件夹中的许多未知模块 - Many unknown modules in node_modules folder 我是否必须将我创建并想要导入的任何脚本/模块放置在 node_modules 文件夹中? - Do I have to place any scripts/modules I create and want to import within the node_modules folder? 我可以通过package.json将依赖项加载到node_modules以外的单独文件夹中吗 - can I load dependencies in a separate folder other than node_modules via package.json Cloudlinux NodeJS 要求将应用程序的节点模块存储在名为“node_modules”的符号链接指向的单独文件夹(虚拟环境)中 - Cloudlinux NodeJS demands to store node modules for application in separate folder (virtual environment) pointed by symlink called "node_modules"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM