Use RequireJS to Reference Third-Party JavaScript Libraries

If you want to use third-party JavaScript libraries in your application, you can import the library and add a requirejs statement to your application’s definition.

  1. Open the app-flow.json file for your application.

    • In the Web Apps pane, select your application node, then click the JSON tab, or

    • In the Source view, locate the file for your application under webapps.

  2. Add a requirejs statement to the application’s definition. For example, if you’ve added gl-matrix-min.js to your application’s resources under ` …/applications/*`*`/resources/js/`, add:

    "requirejs": {
      "paths": {
        "gl-matrix": "resources/js/gl-matrix-min"
      }
    }

    You can also use an expression as the value. For example, instead of resources/js/gl-matrix-min, enter:

    "requirejs": {
      "paths": {
        "gl-matrix": "{{ 'resources/js/' + $initParams.resourceFolder }}"
      }
    }

    Either way, make sure the requirejs entry is a sibling of the id or description entries. If a requirejs section already exists, simply add your entry under paths.

  3. To load and use your library in a module, use the define statement to make your library a dependency for your module. In your JS file, enter, for example:

    define(['gl-matrix'], (glmatrix) => { 
              'use strict';
     ...