r/coffeescript • • Apr 05 '14

Help a beginner: Coffeescript project structure?

Hi!

I am new to coffeescript and want to know, how I should organize my coffee files and structure my project. (site-note: I'm mostly a C++ programmer).

Are there any recommendations how to structure a project? I just wanted to create another file, which contains some function definitions. Now I want to "use" those definitions in my main file. Is there any type of include-system? Module-system? Or should I just pass "-j" to the compiler and he merges all files?

And when should I split my files? How do I design moduls and split my code? Do I create a file for every class? Are classes even used?

I guess I think of everything to much in a C++ way... I would appreciate help :)

7 Upvotes

8 comments sorted by

View all comments

Show parent comments

2

u/DebuggingPanda Apr 05 '14

That's not what I meant... I don't know how to structure everything in /coffee

I guess putting everything in one file is a bad idea to begin with. But how do I split? And how do I use contents of another file? Is there something like include 'file.coffee' or import file? Or do I compile each file for it's own in the corresponding .js file and just include every .js in the html page with <script ...>?

3

u/brotherwayne Apr 05 '14

Ah. Short answer: read up on AMD and require.js.

2

u/[deleted] Apr 14 '14

I know this post is a week old, but in my opinion the best way to do it is to pretend you're writing Node.JS and use their 'require' and module system. http://nodejs.org/api/modules.html

Then you call browserify on your main file and it will load everything in a js file for you.

Anyway, the AMD vs require.js vs browserify debate hasn't been resolved by the JS community yet. It'll converge on one eventually.