Dependency Management and Build Tool for JavaScript

I have many pieces of JS and shared by several projects. I must either copy them to one file for each project, or use them as separate files in cdn. Both are bad ideas.

Is there any dependency management and assembly tool like Maven for JavaScript? Ideally, this will require a set of js dependencies and build a single js file that can be served on cdn.

I can write a script for this. But I'm looking to find something comparable to Maven for JS.


Update 2014: Based on the answers here, and my next research is the most popular tools:

Bower, NPM, RequireJS, Browserify, Webpack, Grunt, Gulp

+7
source share
3 answers

There RequireJS , but this is something other than Maven, and what you ask for is different than Maven too. There are any number of JS combiner / minifiers, like jekyll-combiner and a million more.

If you are using Maven, you might be interested in JavaScript Maven Tools . If you do not, I don’t know a single way to specify, load, combine, etc. For custom build systems. Some of the node.js materials may be useful, but I have never used this outside the context of node.js, so I'm not sure.

+5
source

http://webjars.org/ JS library packages as JAR files and makes them available in Maven.

RequireJS is not a replacement for WebJars; he complements it. RequireJS will use the public JS files (on the CDN) at runtime, while Webjars will load the necessary files at build time and you accept them yourself.

Since most JS files are not hosted on CDNs, I use Webjars to load the necessary JS files at build time and reference them using RequireJS . Thus, I get the best of both worlds.

+4
source

Take a look at grunt . This is a very flexible build tool for javascript projects. Used by the jquery team and other large projects. It combines, minimizes, tests, lint js files, wtitten in javascript, has dozens of plugins for what you want.

+3
source

All Articles