-
Notifications
You must be signed in to change notification settings - Fork 15
The JSX resource converter
The JSX resource converter is an example of an Aggregator extension which implements the com.ibm.jaggr.service.resourceconverter
extension point. The implementation can be found in JSXResourceConverter.java
. It converts JSX files to JavaScript files. To use this resource converter in your application, you would add the following markup to the plugin.xml of the bundle that instantiates the Aggregator (the ability to pass options via the options
init-param was added in version 1.3.5):
<extension
id="converter.jsxResourceConverter"
point="com.ibm.jaggr.service.resourceconverter">
<converter class="com.ibm.jaggr.core.impl.resource.JsxResourceConverter">
<init-param name="JSXTransformer" value="resources/transformer.js"/>
<init-param name="options" value="{harmony: true}"/>
</converter>
</extension>
And add the resourceconverters
init-param to the <servlet>
tag for the Aggregator:
<init-param name="resourceconverters" value="converter.jsxResourceConverter"/>
The JSXTransformer
init-param specifies a URI to the JSX Transformer JavaScript code on the server. If this resource is located in the same bundle that is defining the servlet, then this can be a relative URI as in the example. If it is in a different bundle, then you can use an absolute URI with the file
or namedbundleresource
protocol. An implementation of the JSX transformer can be found in the test resources, or downloaded from the React site.
The JSX resource converter works as follows: Any request for a JavaScript resource (.js extension) that cannot be satisfied because the JavaScript resource does not exist, but for which there is a JSX resource (.jsx extension) with the same base name in the same directory, will be satisfied by converting the content of the JSX resource to JavaScript and providing the converted content as the content of the missing JavaScript resource. Note that the converter does not 'create' the missing JavaScript resource in the source location, but it does cache the converted content so that it can be provided more efficiently on subsequent requests for the same resource.
The JSX resource converter uses a browserified
packaging of the JSXTransformer
running in Rhino
on the server to perform the JSX to JavaScript conversion.