Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

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?

share|improve this question
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. –  troglodite 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. –  troglodite Jan 2 '14 at 23:41

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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