简体   繁体   English

什么是AngularJS中的node_modules目录?

[英]What is node_modules directory in AngularJS?

I am exploring AngularJS tutorial project and found it has node_modules directory inside, which size if 60 megabytes. 我正在探索AngularJS教程项目,发现它里面有node_modules目录,大小如果是60兆字节。

Does simple clientside javascript project really need so huge corpus of unknown data? 简单的客户端javascript项目真的需要如此庞大的未知数据语料库吗?

I tried to delete this directory and project still works. 我试图删除此目录,项目仍然有效。 I suspect it somehow relates with node.js and it's npm but how? 我怀疑它与node.js什么关系,它是npm但是怎么样? Suppose I need to run my project on some conventional web server (not node.js), then how to know, which files/directories are unneeded? 假设我需要在一些传统的Web服务器(而不是node.js)上运行我的项目,那么如何知道哪些文件/目录是不需要的?

Many javascript libraries require to use bower to install them. 许多JavaScript库需要使用bower来安装它们。 If I use bower, does this mean I need to keep node_modules ? 如果我使用bower,这是否意味着我需要保留node_modules

The node_modules directory is only for build tools . node_modules目录仅适用于构建工具

The package.json file in the app root defines what libraries will be installed into node_modules when you run npm install . 应用程序根目录中的package.json文件定义了运行npm install时将在node_modules npm install

Very often with an angular app, on your dev machine or on a build server, you use other Javascript libraries from npm (a node.js package manager) to build your angular app. 通常使用角度应用程序,在您的开发机器或构建服务器上,您使用来自npm(node.js包管理器)的其他Javascript库来构建您的角度应用程序。 Tasks can be concatenating resources, using CSS preprocessors like LESS or SASS, minification, replacing of values, etc. etc. The most common tools for managing and running these tasks are called grunt and gulp , which are installed through npm as well. 任务可以使用CSS预处理器(如LESS或SASS),缩小,替换值等来连接资源。管理和运行这些任务的最常用工具称为gruntgulp ,它们也通过npm安装。

When you deploy your app, you only distribute the resulting build, not any of the source files or build tools. 部署应用程序时,只分发生成的构建,而不是任何源文件或构建工具。

It is of course possible to write an AngularJS app without building anything. 当然可以在不构建任何内容的情况下编写AngularJS应用程序。

edit from comments: When you dive into Angular more, there are more advanced techniques of using libraries installed by npm even in the client app, you then selectively choose the ones you need, not the whole 50MB+ thing. 从评论中编辑:当您深入了解Angular时,即使在客户端应用程序中也有更多使用npm安装库的高级技术,然后您可以选择性地选择所需的库,而不是整个50MB +。 I'd recommend staying with the basic approaches until you get a good grasp on them though. 我建议保持基本方法,直到你掌握它们为止。

NPM is the node package manager, which installs packages locally into a project, specifically, into the node_modules folder. NPM是节点包管理器,它将包本地安装到项目中,特别是安装到node_modules文件夹中。 From there the package code can be included into a project, yes, can is the important word there. 从那里包装代码可以包含在项目中,是的, 可以是那里的重要单词。

The browser has no way to include modules in code (yet), so you need to use a library that can expose node's commonJS style modules. 浏览器无法在代码中包含模块(因此),因此您需要使用可以公开节点的commonJS样式模块的库。 Browserify and Webpack are two popular methods of doing so. Browserify和Webpack是两种流行的方法。

Angular complicates this by introducing its own module system, which more closely resembles AMD-style modules. Angular通过引入自己的模块系统使其复杂化,模块系统更类似于AMD风格的模块。 There are ways around this, so that you can use node-style modules, maybe your project uses those. 有很多方法,所以你可以使用节点式模块,也许你的项目使用这些模块。

Using npm for managing dependencies is a great idea, its a fantastic package manager. 使用npm来管理依赖关系是个好主意,它是一个出色的包管理器。 It is likely in your case though that the project is only built using node and that the node_modules folder contains dependencies only related to the build. 在您的情况下,可能的情况是项目仅使用node构建,而node_modules文件夹包含仅与构建相关的依赖项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM