首页 > 解决方案 > 是否有工具可以从 node_modules 中删除不需要的文件,甚至从使用过的包中删除?

问题描述

这里的用例是 AWS lambda。如今,npm 模块包含所有文档、测试、示例、网站等。所以当我们上传 zip 文件时,它包含了所有不需要的文件。

标签: amazon-web-servicesaws-lambdanode-modulesserverlessaws-serverless

解决方案


这是另一个做同样工作的模块,值得一试https://github.com/tj/node-prune

(来自自述文件)

安装

从来源:

$ go get github.com/tj/node-prune/cmd/node-prune

从二进制到./bin/node-prune

$ curl -sfL https://install.goreleaser.com/github.com/tj/node-prune.sh | bash

从二进制到/usr/local/bin/node-prune

$ curl -sfL https://install.goreleaser.com/github.com/tj/node-prune.sh | bash -s -- -b /usr/local/bin

用法

在您的应用程序目录中:

$ node-prune

files total 27,330
files removed 3,990
size removed 13 MB
   duration 200ms

别的地方:

$ node-prune path/to/node_modules

files total 27,330
files removed 3,990
size removed 13 MB
   duration 200ms

推荐阅读