origin Class
Facilitates the configuration of YUI Core modules and other groups to be served from the express app in a form of origin server.
var express = require('express'),
expyui = require('express-yui'),
app = express();
expyui.extend(app);
// registering a group called app
based on a folder generated by shifter
or any similar tool.
app.yui.registerGroup('app', '/path/to/build/groupName', 'loader-app');
app.use(expyui.expose());
app.use(expyui.static('/path/to/build'));
In the example above, the group/bundle should be built into the /path/to/build
prior
to registering the new group. This process is normaly carry on by the locator
instance,
or using shifter
directly. But once express-yui
receive the information about the
new group, it will automatically provision that new group into the client side by
using the loader-<groupName>
module as the meta module.
Item Index
Methods
applyGroupConfig
-
groupName
-
loaderConfig
Set a custom loader configuration for the group.
Here is an example of how to use it.
app.yui.applyGroupConfig('app', {
maxURLLength: 2048,
comboBase: "/combo?"
comboSep: "&"
});
Parameters:
-
groupName
Stringthe name of the group used by loader.
-
loaderConfig
Objectcustom loader configuration for the group.
registerGroup
-
groupName
-
groupRoot
-
metaModuleName
Register a group by defining the group configuration for the loader.
Groups can be served from origin app or from CDN by calling applyGroupConfig
or by setting yui default base
, yui default root
and yui combo config
thru
app.set()
.
Here is an example on how to use it, assuming that the YUI metadata are
located in the build
directory under the app root.
app.yui.registerGroup('app', __dirname + '/build', 'loader-app');
Parameters:
-
groupName
Stringthe name of the group used by loader.
-
groupRoot
Stringfilesystem path for the group. This will be used to analyze all modules in the group.
-
metaModuleName
Stringoptional module name to denotate the yui module that holds the metas for the group. Default value:
loader-<groupName>
setCoreFromAppOrigin
-
loaderConfig
Set YUI Core Modules from the same origin as to where the application is hosted.
This is not recommended for production and instead you should use a
cdn
to server the build folder, but it is a very useful feature for
development. Here is an example on how to use it:
app.yui.setCoreFromAppOrigin();
Parameters:
-
loaderConfig
Objectoptional loader configuration for the core