JavaScript – Proper Way to Compile a JavaScript Project

javascriptlibrariesopen source

I'm developing a small open-source javascript library, and I was wondering about the proper method for compiling the source into one javascript file.

It's easier to develop if the code is split into multiple files, but libraries are included as one large file when used in another application. My current "compilation" method involves using a makefile to copy each submoudle into the main file and then minify it. What is the proper way to do this?

Best Answer

I would look at tools like Browserify in order to combine your code. When you use Browserify, your code is your build tool. Browserify gives you all the benefits of writing code in node (no anon functions to avoid globals, npm, simple requires, imports instead of namespaced globals) and it allows you to package that code to run on the client with one command and only load one file.

You can checkout my open source js framework Luc JS for an example. It runs on node and IE6. I'm able keep the code modular and build the single browser file with a one line command.

Related Topic