require Configuration

You can configure a require Object by associating a script to a JSON-formatted configuration file using the @NAmdConfig JSDoc tag within your script.

Important:

Configuration of a require Object is optional and for advanced users only. If you must configure a require Object, the @NAmdConfig JSDoc tag is suited for general use and is the preferred way to configure a require Object. However, existing scripts with calls to require.config() can use this method with a context argument (although not preferred). Ensure that the call includes a context parameter and that its value is not a file path.

If you include a valid @NAmdConfig JSDoc tag, SuiteScript implements the require configuration settings (in the specified file) before loading dependencies. Using different require configuration files allows you to run multiple client scripts with different configurations based on the @NAmdConfig JSDoc tag included in each script. This also supports re-use by letting you use a common configuration across multiple scripts.

To configure a require Object, add the @NAmdConfig JSDoc tag and provide the path to the configuration file. Configuration files must be located in the File Cabinet. For example:

             /**
    * @NAmdConfig /SuiteScripts/configuration.json
    */ 

        

SuiteScript will require a custom entry point module and its dependencies using the AMD configuration settings in the specified configuration file. Your require configuration must be in JSON format. For example:

          {
       "baseUrl" : "/SuiteBundles"
} 

        
Important:

Ensure that your require configuration files use JSON syntax (and not JavaScript syntax). For more information about JSON, visit http://json.org/. You can use JSON.stringify(obj) to convert a JavaScript object value to a key-value pair string in JSON form.

For a list of supported configuration parameters, see require Configuration Parameters. Properties that can hold feature metadata, aliases, paths, package, and mapping information related to a module id are supported.

require Configuration Parameters

SuiteScript accepts the require configuration values described at https://github.com/amdjs/amdjs-api/blob/master/CommonConfig.md (version fd45c71).

You can use the @NAmdConfig JSDoc tag to specify a configuration file that defines configuration values.

The following configuration parameters are supported in a require Object configuration file:

Parameter

Type

Required / Optional

Sample Usage

Since

baseUrl

string

optional

  • To configure a shorter relative path by indicating the root folder that holds the modules in the File Cabinet.

2015.2

config

Object

optional

  • To assign attributes, such as metadata.

2015.2

map

Object

optional

  • To specify an alias.

  • To handle multiple names for a module,

  • To load a set of identically-named but unique modules, such as dependency on multiple module versions.

2015.2

packages

Object[]

optional

  • To configure a special lookup suitable for traditional CommonJS packages that you want to use as a custom module.

2015.2

paths

Object

optional

  • To create a named alias to a path,

  • For testing purposes, pass in an object that serves as a mock-up of another module.

  • To set up a custom name for a SuiteScript module.

2015.2

shim

Object

optional

  • To prepare a non-AMD JS library for loading.

2015.2

Refer to https://github.com/amdjs/amdjs-api/blob/master/CommonConfig.md for examples of each configuration parameter.

Important:

Configuration of a require Object is optional and for advanced users only. If you must configure a require Object, the @NAmdConfig JSDoc tag is suited for general use and is the preferred way to configure a require Object. However, existing scripts with calls to require.config() can use this method with a context argument (although not preferred). Ensure that the call includes a context parameter and that its value is not a file path.

Related Topics

require Function
require([dependencies,] callback)

General Notices