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?

  • 1
    As far as I know, that is the proper way. – Karl Bielefeldt Jan 2 '14 at 22:30
  • That's what I've always done. – hkk Jan 2 '14 at 23:39
  • 1
    Since Javascript is written for, and interpreted by, browsers, it doesn't have a default, or "proper" system for this. However, many minifier programs support combining multiple programs together. – hkk Jan 2 '14 at 23:41

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.