Jump to content

How do you organize your projects?


Recommended Posts

Coming from object oriented languages, JavaScript is a bit of a dark art for me. I've found simply concanating all your files together works okay but sooner or later gets out of hand and makes debugging difficult. Not to mention, order matters in some cases and we don't have much control over this.

How does everyone manage their classes and workflow? I've seen RequireJS but it seems to be under hot debate and things like browserify. I guess another option is a script tag per script.


Link to comment
Share on other sites

for development I keep an index.html file with separate script tags for each of my files. for deployment, I use grunt to concat and minify the files into a single script.


I also have my own version of 'require' with which I specify dependencies. it doesn't do any actual script loading, but it ensures I have my dependencies right, and lets me run multiple copies of my code on the same page, should I so desire. (see this post)

Link to comment
Share on other sites

You don't need to have a file per class like in Java.

You may group your classes in files the way you feel more convinient for you (like in Ruby)

Ex : you can have a file per game state and/or a file per game entity (player, ennemies, non player characters, etc) and/or a file per transversal helper library (maths, physics, third party lib)


here is an exemple : http://toastedware.com/?p=258

but someone else could prefer another organization


you definitely have to concat all your stuff for deployment

the less http requests, the better for your browser and user experience

Link to comment
Share on other sites



I have the same scheme in mind as you and am in fact following a similar plan:  Each module a separate script file during development and a hand-rolled dependency checker.  I am very near to release on the project I am working on and like you, am interested in using grunt to concat and minify my files.  I am fairly new to grunt, and was wondering if you would be willing to share which plugins you are using and/or a sample project?  It would save me some time and I'm sure others would be interested.  On the other hand, I do realize that you had to put your own time into this and I am essentially asking something for nothing.  If you are not comfortable with this request or don't have time to put something together, that's totally cool.

Link to comment
Share on other sites

no worries. my Nadion library (add-on for Phaser) uses grunt to concat and minify files - but I believe Phaser uses the same grunt modules (grunt-contrib-concat and grunt-contrib-uglify), so you can also just look at the Phaser 'Gruntfile.js'.


it's relatively straightforward, but if you have any questions I'm happy to (try to) help

Link to comment
Share on other sites

  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...