Skip to content

Building: Command Line

Ryan Lane edited this page Feb 8, 2019 · 1 revision

Note

The r.js file included in this repo has been modified from the original version 2.3.5 to provide additional Source Map generation options. If required, r.js can be downloaded directly from the source r.js repo or installed via npm:

npm install requirejs

r.js

r.js is a command line tool for running JavaScript scripts that use the Asynchronous Module Definition API (AMD) for declaring and using JavaScript modules and regular JavaScript script files.

It is part of the RequireJS project, and works with the RequireJS implementation of AMD.

r.js is a single script that has two major functions:

  • Run AMD-based projects in Node and Nashorn, Rhino and xpcshell.
  • Includes the RequireJS Optimizer that combines scripts for optimal browser delivery.

Node

r.js main.js

Requires Node 0.4 or later.

r.js allows using Node modules installed via npm. For more info see the Use with Node docs.

Optimizer

What Makes It Special

The optimizer is better than using a plain concatenation script because it runs require.js as part of the optimization, so it knows how to:

  • Use Loader Plugins to load non-script dependencies and inline them in built files.
  • Name anonymous modules. If your optimization step does not do this, and you use anonymous modules, you will get errors running the built code.

Relative path resolution rules

In general, if it is a path, it is relative to the build.js file used to hold the build options, or if just using command line arguments, relative to the current working directory. Example of properties that are file paths: appDir, dir, mainConfigFile, out, wrap.startFile, wrap.endFile.

For baseUrl, it is relative to appDir. If no appDir, then baseUrl is relative to the build.js file, or if just using command line arguments, the current working directory.

For paths and packages, they are relative to baseUrl, just as they are for require.js.

For properties that are module IDs, they should be module IDs, and not file paths. Examples are name, include, exclude, excludeShallow, deps.

Full Documentation

Full documentation for RequireJS Optimization can be found at https://requirejs.org/docs/optimization.html.

Command Line Usage

Note r.js must be run in an elevated prompt in order to add or override existing files in the CustomSpace directory.

Manually Running

A basic command to run the optimizer using the build-template.js configuration file:

node r.js -o build-template.js

Automated

The batch file build.bat has been provided run the optimizer for the following:

Out-Of-The-Box

CustomSpace