🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
npm使得Javascript开发者易于分享和复用代码,并使你分享的代码易于更新。 > npm makes it easy for JavaScript developers to share and reuse code, and it makes it easy to update the code that you're sharing. 如果你使用Javascript有一阵子了,你或许听说过npm:npm使得Javascript开发者易于分享其为解决特定问题而编写的代码,且可供其他开发者在他们自己的应用中复用这些代码。 > If you've been working with Javascript for awhile, you might have heard of npm: npm makes it easy for Javascript developers to share the code that they've created to solve particular problems, and for other developers to reuse that code in their own applications. 当你依赖于来自其他开发者的这些代码是,npm就会使检查代码更新和下载更新变得相当容易。 > Once you're depending on this code from other developers, npm makes it really easy to check to see if they've made any updates to it, and to download those updates when they're made. 这些可复用代码被称作“包”,有时也叫做“模块”。包仅是一个包含一些文件的目录,以及一个名称为“package.json”的文件,此文件中包含了一些有关此包的元数据。一个典型的应用,比如一个网站,将会依赖于几十上百个包。这些包通常很小。通常的想法是,你创建一个小型代码块,以解决一个问题并很好的解决。这就使你能通过这些小型的被分享的代码块,编写出大型的自定义的解决方案 > These bits of reusable code are called packages, or sometimes modules. A package is just a directory with one or more files in it, that also has a file called "package.json" with some meta data about this package. A typical application, such as a website, will depend on dozens or hundreds of packages. These packages are often small. The general idea is that you create a small building block which solves one problem and solves it well. This makes it possible for you to compose larger, custom solutions out of these small, shared building blocks. 这样做有很多好处。它使你的团队有可能通过引进专注于某个问题领域的专家编写的代码,以此为基础来发挥自己组织的专长。即使不复用你的组织外人们写的代码,你使用此类基于模块的方法也能真正地帮助你的团队更好地协作开发,并且也可以使跨项目的复用代码成为可能。 > There's lots of benefits to this. It makes it possible for your team to draw on expertise outside of your organization by bringing in packages from people who have focused on particular problem areas. But even if you don't reuse code from people outside of your organization, using this kind of module based approach can actually help your team work together better, and can also make it possible to reuse code across projects. 你可以通过浏览npm官网寻找代码包,以帮助你构建应用。当你浏览这个网站是,你会发现各种不同的包。你会发现很多node模块。npm是作为node的包管理器开始的,所以你可以找到很多可用于服务器端的包。也有很多包可以为你在命令行中添加命令。此时,你就会发现,有很多包可以用于前端浏览器。 > You can find packages to help you build your application by browsing the npm website. When you're browsing the website, you'll find different kinds of packages. You'll find lots of node modules. npm started as the node package manager, so you'll find lots of modules which can be used on the server side. There are also lots of packages which add commands for you to use in the command line. And at this point you can find a number of packages which can be used in the browser, on the front end. 现在你已经知道npm能干什么了,那我们来谈谈它如何工作的。当人们谈起npm时,他们可能会说三件事: 1. 他们可能会提及官网,这个我们刚才已经看过了; 2. 也可能会谈及注册池,注册池是你可以享受人们共享代码的庞大的包数据库; 3. 或第三个,就是客户端。当开发者决定要共享她的代码时,可以使用装在电脑上的npm客户端来将代码发布到注册池中。一旦注册池中此包拥有了入口,其他开发者就可以使用npm客户端从注册池中下载安装此包了。 > So now that you have an idea of what npm can do, let's talk about how it works. When people talk about npm, they can be talking about one of three things. They could be talking about the website, which we've just been looking at. Or they could be talking about the registry, which is a big database of information about packages that people are sharing. Or the third thing they could be talking about is the client: when a developer decides to share their code, they use the npm client which is installed on their computer to publish that code up to the registry. And once there's an entry for this package in the registry, then other developers can use their npm clients to install the package from the registry. The entry in the registry for this package is also reflected on the website, where there's a page dedicated to this new package. 好了,这就是npm。它是复用其他开发者代码的一种方法,也是你与他们分享代码的一种方式,使管理不同版本的代码变得容易。 > So that's what npm is. It's a way to reuse code from other developers, and also a way to share your code with them, and it makes it easy to manage the different versions of code.