When comparing Component vs npm + Browserify, the Slant community recommends npm + Browserify for most people. In the question“What are the best open source front-end package managers?” npm + Browserify is ranked 1st while Component is ranked 10th. The most important reason people chose npm + Browserify is:
If you're using node.js as your backend, you gain a lot of flexibility by using the same package manager for the frontend and backend, making it much easier to share code without adding one more tool to an already large toolbase.
Ranked in these QuestionsQuestion Ranking
Pros
Pro Vertically integrated with the build process
Component handles more than just package management; it also deals with the build process and bundling, so you don't have to find and manage a separate solution. This lets you get up and running faster with less to worry about.
Pro Also manages non javascript components
Components can be html snippets or css in addition to Javascript, and are treated as first class objects by being converted into Javascript modules that load styles and markup as strings.
Pro Components are more structured and thus have more inter-compatibility
Components can be javascript, style and markup, they are bundled in a way that makes it possible to load in entire UI chunks. This means less flexibility, but the components that are available are easier to work with.
Pro Designed with ES6 modules and Web Components in mind
Component is designed as a current-day solution for the currently proposed ES6 modules and Web Components, making it more in-line with the direction the web is going in the future.
Pro Encourages simpler and smaller components
Components are encouraged by convention to be small and single-use, meaning that the packages in the community's ecosystem are easier to use and combine together. More complex components use dependency resolution to compose smaller components so that components stay limited in scope.
Pro Easy dependency management
Component provides you with a flat dependency tree. This results in easy dependency management. A flat dependency tree is important for file size optimization, so you don't end up loading multiple copies of the same library, or deeply nested dependencies that bloat up.
Pro Best way to share code with the backend
If you're using node.js as your backend, you gain a lot of flexibility by using the same package manager for the frontend and backend, making it much easier to share code without adding one more tool to an already large toolbase.
Pro Huge active ecosystem
Npm gains a lot from its large community, and the activity from node.js gives npm the largest set of active repositories. Since so many people already use npm, chances are the library you need has already been added to npm, and many new authors are writing their libraries with npm in mind.
Pro Client side shims provided by Browserify
Browserify provides client side versions of non I/O related built in npm modules. This allows you to use the path manipulation, crypto, and zip libraries on the client side.
Pro Support multiple bundles
Browserify allows splitting up bundles among multiple pages to get the benefit of caching for shared, infrequently-changing modules, while still being able to use require().
Pro All modules must implement CommonJS modules which leads to cleaner dependency management
Because all npm modules need to follow the CommonJS format, it's much easier to set up dependencies through the require function.
Pro Easy to create bundles
Because of the nature of Browserify, it's easy to require
different dependencies and concatenate them into one minified file.
This helps with performance and load times, especially for mobile devices.
Pro Can also flatten the dependency tree with dedupe
npm dedupe lets you flatten the dependency tree.
Npm has a very handy dedupe tool. What this tool does is that it checks the dependency tree to find modules that depend on third dependencies. If a suitable version for all modules exists, it keeps that version and deletes any other versions that are not needed.
For example, in this dependency graph:
a
+-- b <-- depends on c@1.0.x
| -- c@1.0.3
-- d <-- depends on c@~1.0.9
-- c@1.0.10
dedupe will transform it to:
a
+-- b
+-- d
-- c@1.0.10
What it did was to make sure that both b
and d
got their dependency met by a single c
module. It then deleted all the unneeded versions of the c
module.
Pro Browserify shim allows you to use non Common JS formatted packages
Browserify shim is a transformation extension for Browserify that lets you load in libraries that do not follow the Common JS structure (using an exports module). This allows you to explicitly define what globally defined variables should be exposed by a require
statement so you can control how you load in these poorly formatted libraries safely without polluting the global scope.
Because the Common JS style loads in required libraries within a closure, any variables defined in a library will not pollute the global scope. Browserify shim lets you define which variables defined within that closure to map to the exports
variable that Common JS expects in a safe and explicit way through declarations in your project's package.json
file.
Pro Can include HTML, CSS and images as well
Packages hosted with NPM do not include just JavaScript. Other assets, like static ones (HTML, CSS and images) are included.
Cons
Con No longer maintained
Component is no longer being developed/maintained, so there will be no new features or bug fixes.
Con Cannot add modules that are not on Github
While using Github as a backend database for Component makes things a lot easier, as there's no need to add other authorization credentials to use modules, it means that modules that aren't on Github cannot be added.
Con Familiarity with Node is required
Browserify's documentation assumes that you have some familiarity with Node before starting to work with it. Some methods are not explained very thoroughly and others are assumed to be already known by the developer.
For example, Node's module.exports
is not explained, it's just mentioned that browserify modules can be exported using it. Which is fine, but for a developer not used with Node, or a front-end engineer that has never used Node it can be confusing.
Con Does not guarantee reproducible builds
Con Needs to create a bundle in every change
That makes debugging more difficult and requires extra time to create the bundle again for every change.
Con Post-install scripts
Packages shouldn't need post-installing. They should be an enclosed unit. This is another potential attack vector.