In the Web platform from Node.js learn anything in this article, we explore the benefits created by the developer for developers of small-scale abstract brings. In this article, we come to understand how and why this style of development should be incorporated into your own Web front end.
Choose your own way
As a user of small module, if you do not accept the changes made to rely on, then you can rely on for another. Perhaps the application will use the new version of a module (for example 2.x), while another application is dependent on the use of the old version (for example 1.x). In Node, because dependent lookup is from neighboring node_modules catalog Start, and then step by step up the file system, even if the required number of different versions of the same module, this approach is to meet the demand. If the versions match, then only use one copy.
Browser npm module? It is not Node things?
You may be wondering how can without the use of hundreds of script tag or not RequireJS profile entries using so much so much dependent on the maintenance situation. Maybe you want to know how to use modules from npm browser to easily create SVG elements. And other such modern tools Webpack Browserify and let it become possible, they will be tracked by the same Node CommonJS require statements used in the application dependency graph. They make a large package file module visible to each other, and you will be incorporated in the page, you can come in a single script tag.
I know a lot of people to put multiple versions of the browser jQuery idea surprised. Yes, some do indeed terror, although made to streamline and gzip compression, but jQuery will still be 30KB in size. However, transfer two, three, or even four 2KB size replica of the library has been insignificant compared to them, in particular able to avoid doing so manually resolve dependencies and upgrade jQuery plug-ins as well as those installed. Even so, you should only be included in the application in a number of modules, and these modules are also dependent on many incompatible modules and the circumstances to do so, because npm 3 by default will try to tie the module catalog. Feel free to use more than 100,000 registered npm modules through a simple installation.
Where the boundaries
We start to understand some of the terminology: the package refers to the npm registry can be published or unit uses the git repository. But CommonJS, the module file is one to one. Therefore, a package can include a plurality of modules, but usually, a npm package is itself a module.
Responsibilities package definition is a most difficult thing. If the scope of the package is too large, then there will be disruptive change, the consequence is the destruction of the ecosystem. Similarly, if a package has many dependencies so disruptive changes and Bug would cause the entire system cascading updates, whether open source or internal use is true. In the scope of the package design, the principle is a good software components cohesion. Essentially, if several components vary together, then they should belong to the same package. If not, then please be extracted!
To build applications by small modules than you think much simpler. Your application may have a lot of abstraction, abstract to determine which should have its own package is actually a very difficult thing. First, if only abstract platform, and to provide general-purpose facade, it is preferable to provide an open-source package. Such as GitHub and Bitbucket and other services are well suited to this, if you are using a browser or Node, then of course you should publish the results of their work to the npm registry. Of course, the ecosystem in other languages also has its own package management solution.
Once you have a lot of small modules, you can iterate their designs, which combined to build a higher level of abstraction. You can fearlessly destroy APIs, because modern tools and semantic version can ensure that consumers are able to choose from, everything will be rapidly evolving. This is the true meaning of the change.