|
Will Binns-Smith is a love of full-stack JavaScript engineer, likes to solve real problems through technology. He developed Bonobos.com front-end shopping cart functionality. Will like to work one on one with designers, PC site will be converted to the site for smaller touch devices. Recently, Will wrote an article, which talked about the Node.js practices and characteristics of front-end applications worth studying.
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.
Another common problem is that doing so will increase the transmission to the browser JavaScript file size. In the new version of npm, this module tree using a flat form, and will apply to each of the dependent to provide the required version. By this way, you will not need to pass any copies of the library, while meeting the requirements of each module. In addition, there is a more novel called rollup package manager, it uses the ES2015 module format, only a subset of the package you are importing module.
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!
Remember, with the majority of the aid package manager npm, a packet does not necessarily need a dedicated warehouse. If the burden of excessive Pull Request prevented the release of new modules process, then please consider creating a new repository, also released each packet. Babel is an open source JavaScript compiler, in this way it is maintained in a single repository of more than 100 packages, which greatly enhance the efficiency, but will also be published to each package in the npm.
It is worth noting that a limit (another JavaScript Package Manager) The Bower is that it uses Git repository (or tarballs) as a receiver module code the way, so it needs to create one repository for each package. My suggestion is to use npm.
try
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.
If the application is internal business logic provides a reusable abstraction, such as internal services or API wrapper, then the others in the organization who would benefit from a separate package. In Atlassian, we have a lot of small JavaScript client to access and other reports or analysis services. In addition, there is a general-purpose package, which is used to quickly start Atlassian Connect implementation in new products. For source code management, my advice is not to serve as a basis for each warehouse, so as to create an internal ecosystem composed of many small modules posed. Bitbucket Cloud may change with the size of the team and the horizontal expansion and Bitbucket Server. When publishing packages, npm provided on its cloud service for proprietary modules, and provides a self-hosted services to warehouse management as a source of beneficial supplement. You can even by Bitbucket Cloud Storage module to be easily installed npm: Just Run npm install bitbucket: user / repo can be.
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. |
|
|
|