我如何 tar node_modules 文件夹并让 NodeJS 从中提取

How do I tar the node_modules folder and have NodeJS pull from that

我最近做的一个项目总共有15000个文件,众所周知,这些文件通常都是小文件。成千上万的文件可能让每个人都头疼,我想知道是否有办法将 node_modules 文件夹打包并告诉 nodejs 从该文件夹中提取所有依赖项。

我的理解是,一个模块不应该写入它自己的文件夹,因为它可能没有所需的权限,所以我认为这可行。

它不一定是 tarball,只需不到 10 个文件即可包含所有内容。 package.json.

中的每个依赖项也可以是一个文件

请参阅 GitHub 上的 Node 问题 #1278 - 压缩包:

和 npm 在 GitHub 上的问题 #49 - 添加选项以存储压缩的依赖项:

我一直在为我们的 docker 构建考虑类似的问题,并且正在查看 Yarn and using the Yarn Offline Mirror. It should get you your 1 file per dep. You'll probably also want to turn on automatic pruning