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.
-
Open the
app-flow.jsonfile 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.
-
-
Add a
requirejsstatement to the application’s definition. For example, if you’ve addedgl-matrix-min.jsto 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
requirejsentry is a sibling of theidordescriptionentries. If arequirejssection already exists, simply add your entry underpaths. -
To load and use your library in a module, use the
definestatement to make your library a dependency for your module. In your JS file, enter, for example:define(['gl-matrix'], (glmatrix) => { 'use strict'; ...