Class AMDWrapper
java.lang.Object
org.apache.tapestry5.services.javascript.AMDWrapper
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:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturn this wrapper instance as aJavaScriptModuleConfiguration
, so it can be contributed to theModuleManager
's configuration.Add a dependency on another module.Add a dependency on another module.setReturnExpression
(String returnExpression) Optionally sets a return expression for this module.
-
Constructor Details
-
AMDWrapper
-
-
Method Details
-
require
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
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
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
-
asJavaScriptModuleConfiguration
Return this wrapper instance as aJavaScriptModuleConfiguration
, so it can be contributed to theModuleManager
's configuration. The resultingJavaScriptModuleConfiguration
should not be changed.- Returns:
- a
JavaScriptModuleConfiguration
for this AMD wrapper
-