4

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?

3
  • 1
    As far as I know, that is the proper way. Commented Jan 2, 2014 at 22:30
  • That's what I've always done.
    – hkk
    Commented Jan 2, 2014 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
    Commented Jan 2, 2014 at 23:41

1 Answer 1

3

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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