NOTE: RequireJS is the legacy module format for the platform. It is no longer being used going forward.

All projects should:

  • use RequireJS to bundle/load their dependencies
  • provide an interface for loading the project as an AMD module

What is RequireJS?

RequireJS is a JS script for loading AMD-style modules. It automatically resolves dependencies in the correct order.

Modules allow us to separate our code into individual components. For more info on why, see “Why Web Modules?

For a simple intro to RequireJS, see “Using RequireJS in AngularJS Applications”.

Loading Dependencies

RequireJS’ r.js will automatically bundle all dependencies into a single JS file for loading. This tool can be utilized for production environments to minimize HTTP requests. The dependencies can be lazy-loaded (the RequireJS default) during development work.

Defining an AMD Module

For maximum compatibility, projects should use a module bundler like webpack or the UMD pattern. This ensures that the project will work with RequireJS, but also work inside apps that don’t use a module loader, or uses a different module API (such as CommonJS).

It is recommended that JHA/Banno-specific projects use a banno/ prefix for the module IDs – for example, banno/mobile for the Mobile Admin app. Namespacing of modules should use this “forward slash” format.