如何减小Node.js应用的大小(或构建它

问题描述 投票:-1回答:1

我建了一个小的Node.js应用,我想把它放到GitHub上,但问题是node_modules太大了。有没有什么办法可以让这个应用在构建的时候变得很小?

javascript node.js npm
1个回答
0
投票

要在GitHub上存储你的项目,而不需要node_modules,你需要创建一个 .gitignore 在您的porject的根目录下(在您的 package.json 文件),并在其中添加node_modules条目。

这个结构应该是这样的。

/project
  ...
  package.json
  .gitignore
  package-lock.json // should NOT be added to the gitignore

And the structure should look like this. .gitignore 看起来应该是这样

node_modules

之后,你需要推动这个 .gitignore 文件到远程仓库(在您的例子中是 GitHub)。

这样做是告诉 git 不要跟踪 node_modules 文件夹内的文件。

从远程(GitHub)拉出项目后,你可以通过使用 npm install 它将在node_modules文件夹中安装你的依赖关系。

© www.soinside.com 2019 - 2024. All rights reserved.