准备部署时如何清理 node_modules 文件夹 [英] How to clean node_modules folder when prepping for deployment
问题描述
在准备部署代码时,我将如何清理 node_modules 文件夹.
How would I go about cleaning the node_modules folder when prepping my code for deployment.
我正在使用 node-webkit 制作应用程序,并且希望在捆绑应用程序的最终版本时包含尽可能少的文件,因为解压缩过程需要一些时间.
I am making an app using node-webkit and would prefer to include the least amount of files possible when bundling the final version of the app as the unzip process takes some time.
我查看了 npm dedupe
并使用 npm install --production
去除重复项并仅获取生产文件,但是我仍然使用 Readme
文件、benchmarks
、tests
和 build
我不需要的文件.
I've looked at npm dedupe
and use npm install --production
to get rid of duplicates and fetch only production files, however I am still left with Readme
files, benchmarks
, tests
and build
files which I don't need.
我希望 node_modules
文件夹中的每个模块最终得到一个 LICENSE
文件(如果存在),package.json
以及模块运行所需的任何其他内容,仅此而已.
What I would like to end up with for each module in the node_modules
folder is a LICENSE
file if it exists, the package.json
and anything else that I need for the module to run, but nothing more.
问题:如何为 SCM 提交自动清理 node_modules 目录 有点朝着相同的方向发展,但它谈论的是提交,所以并不是我真正想要的.
The question: How to automatically clean a node_modules directory for a SCM commit was heading somewhat in the same direction, but it is talking about committing so not really what I am looking for.
问题:NPM 清洁模块 与我的有些相似,但不完全相同完全在那里.
The question: NPM clean modules again was somewhat along the same lines as mine, but not quite fully there.
这个答案很有帮助,因为它是 dedupe
的更高效版本,用于捆绑最终应用.
This answer helps as it is more efficient version for dedupe
for bundling the final app.
更新
我尝试了从 here 链接的自定义模块,但它即使经过一些摆弄,似乎也无法正常工作.
Update
I tried the custom module linked from here but it didn't seem to work correctly, even after some fiddling about.
说了这么多,我还没有找到正确的答案.
With all that said, I haven't quite found the right answer yet.
这是我正在寻找的示例.
Here's an example of what I am looking for.
在我的项目中,我目前有两个依赖项:socket.io
和 socket.io-client
.
In my project I currently have two dependencies: socket.io
and socket.io-client
.
它们在 110 个文件夹中与 550 个文件一起构成 15 MB.
Together they make up 15 MB with 550 files in 110 folders.
手动清理readme
、makefile
、VC++
构建文件,例如.pdb
和.obj
和其他不必要的文件,我能够将其缩小到 2.74 MB,265 个文件位于 73 文件夹中.
这只有两个模块.
Manually cleaning readme
, makefile
, VC++
build files such as .pdb
and .obj
and other unnecessary files I was able to shrink it down to 2.74 MB with 265 files in 73 folders.
This is with just two modules.
我想知道是否有办法自动执行此操作,最好使用 npm
.
I would like to find out if there is a way to do this automatically, preferably with npm
.
推荐答案
清理node_modules
用于部署webkit 应用程序,这有点困难,因为node_modules 中的模块
目录安装有或没有测试文件 其他 misc 文件,因此,如果模块的所有者,已声明一个 .npmignore
文件,其中包含目录/文件,例如 tests
或 examples
当所有者发布他的模块时,它们将被排除在打包过程之外,但它会照常存在于存储库 (git) 中.
Well cleaning the node_modules
for the deployment for a webkit application, its kind of difficult, because of the modules inside node_modules
directory are installed with or without test files other misc files and so, if the owner of the module, has declared an .npmignore
file with dir/files such as tests
or examples
those will be excluded from packaging process when the owner publishes his module, but it will exist in the repository (git) as normal.
以上内容留在模块所有者手中,如果他/她忘记"制作一个,那么包将包含几乎所有内容.
请注意,由于您不使用
socket.io
或 socket.io-client
的 development
包,这并不意味着您必须npm install socket.io --save-dev
,一个简单的 npm install socket.io -V
将安装生产包,因为它是由其所有者上传的.一种可能的解决方法是执行
grunt
任务,按照您的意愿清理整个 node_modules
.
the above is left in module owners hands, if he/she "forgets" to make one, then package will contain pretty much everything.
Note that since you don't use the
development
package of socket.io
or socket.io-client
it doesn't mean you have to npm install socket.io --save-dev
, a simple npm install socket.io -V
would install the production package as it was uploaded by its owner.
A possible workaround would be to make a
grunt
task, to clean your entire node_modules
as you would like it to be.
一些规则是
test
或tests
目录或*test*.js
文件build
目录(不确定它可能包含一些有时需要的二进制文件)history.md
test
ortests
directory or*test*.js
filesbuild
directories (not sure about it might contain some binaries sometimes that are necessary)history.md
希望我能帮上忙,也看看 Tilemill 以及他们如何部署他们的应用程序.
GruntJS
Hope i helped somehow, also take a look at Tilemill and how they deploy their application.
这篇关于准备部署时如何清理 node_modules 文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!