Comment Project Setup and Dependencies management

In notebook:
FrontEndMasters BackboneJS
Created at:
2016-05-29
Updated:
2019-08-08
Tags:
JavaScript libraries
  git clone git@github.com:quickleft/backbone-comments.git
cd backbone-comments
git checkout -b project-template origin/project-template

# then...
npm install
Found to repo on Sam Breed’s GitHub repo:
http://wookiehangover.github.com/backbone-comments/

some opinions 

  • Require.js for (AMD) modules
  • Bower for dependency managements (package file for dependencies and command line tool to install them). can also use ​bower search​ to find modules/plugins. Similar to npm. Avoid to include several times the same dependency.
  • Grunt.js for building for productions

Require JS

List external dependencies. CommonJS syntax.
  define(function(require, exports, module){
  var $ = require('jquery');
  var _ = require('underscore');
  var Backbone = require('backbone');
  
  module.exports = Backbone.View.extend({
    
  });

});
RequireJS will actually fetch all the dependencies and insert them as ​<script>​ tags in the ​<head>​. Loads everything in the right order. 
It only needs a file system to work (locally for example).

From IE9 and up. Can inspect what’s going on in the script and act on it. Have synchronous looking require statements, that are resolved asynchonously. 
Example of a complex include:
https://gist.github.com/wookiehangover/5776447
Compares of including with an AMD-style syntax, where the dependency array must mach the variables pass to the module. Or the commonJS style syntax above where you declare your dependency and variable on the same line.

Theres a build tool (rjs), that will compile all your dependencies and code into one file.

Talks more about reuquireJS config.
Checks out the master branch of the project.