

each Javascript file follows the CommonJs module format of node, exporting its dependencies via module.exports.each Javascript file is published together with the Typescript type definitions and source maps.the lib folder contains the bulk of the library, in this case the Angular component named HelloWorld.components.js and components.d.ts define the public API of the library.The following are the different components of the library: Lets take a look at what the sample library (named angular2-library-example) looks like when published to npm: the size of CommonJs bundles is smaller (in the case of Angular the gain was around 20%)ĭue to the above-mentioned reasons, the current most convenient format to publish an Angular library is a set of Javascript-only files in the CommonJs module format.CommonJs is the node.js module format, which allows for components to be more simply used in server-side rendering.CommonJs can also be easily consumed by SystemJs.CommonJs is easily consumable by existing popular tools such as Browserify or Webpack.

This happened for a couple of good reasons:

Isolating CSS via component encapsulationĬhoosing a format to publish an Angular libraryĭuring the alpha stage of Angular, the Angular bundles where initially published in SystemJs format, but now they are published in CommonJs (see here).Choosing a format to publish an Angular library - CommonJs.In this post we are going to see how an Angular component library can be built and then consumed using both SystemJs and Webpack.
