Class AMDWrapper


  • public class AMDWrapper
    extends Object
    Used to wrap plain JavaScript libraries as AMD modules. The underlying resource is transformed before it is sent to the client. This is an alternative to configuring RequireJS module shims for the libraries. As opposed to shimmed libraries, the modules created using the AMDWrapper can be added to JavaScript stacks. If the library depends on global variables, these can be added as module dependencies. For a library that expects jQuery to be available as $, the wrapper should be setup calling require("jQuery", "$") on the respective wrapper.
    Since:
    5.4
    See Also:
    JavaScriptModuleConfiguration, ModuleManager
    • Method Detail

      • require

        public AMDWrapper require(String moduleName,
                                  String parameterName)
        Add a dependency on another module. The module will be passed into the generated factory function as a parameter.
        Parameters:
        moduleName - the name of the required module, e.g. jQuery
        parameterName - the module's corresponding parameter name of the factory function, e.g. $
        Returns:
        this AMDWrapper for further configuration
      • require

        public AMDWrapper require(String moduleName)
        Add a dependency on another module. The module will be loaded but not passed to the factory function. This is useful for dependencies on other modules that do not actually return a value.
        Parameters:
        moduleName - the name of the required module, e.g. bootstrap/transition
        Returns:
        this AMDWrapper for further configuration
      • setReturnExpression

        public AMDWrapper setReturnExpression(String returnExpression)
        Optionally sets a return expression for this module. If the underlying library creates a global variable, this is usually what is returned here.
        Parameters:
        returnExpression - the expression that is returned from this module (e.g. Raphael)
        Returns:
        this AMDWrapper for further configuration