RequireJS - Environment Setup


In this chapter, we will understand how to set up the environment for RequireJS. For this, you need to download the latest version of RequireJS library. You can download either the minified version or detailed version.

After downloading, we need to include the require.js file in your libs folder and the structure of your project should be as shown below −


We need to define an html file as index.html where RequireJS is loaded as shown below.

      <script data-main = "libs/main" src = "libs/require.js"></script>
      <h1> RequireJS Sample Page </h1>

Note that only require.js with a RequireJS call is included in the script tag to load the script.

RequireJS in Node

There are two ways to get the Node adapter.

  • npm − You can install the latest release of requirejs from the command prompt as shown below.

npm install requirejs
  • Download r.js − You can download the r.js file from the download page and source from r.js repository page.