score.requirejs¶
Provides all necessary tools to start javascript development using
score.webassets
and requirejs.
Quickstart¶
Configuring the module:
[score.init]
modules =
score.tpl
score.js
score.webassets
score.requirejs
[webassets]
modules = score.requirejs
You can then embed your javascript files in your html with the usual means
provided by score.webassets
. The following example uses jinja2 syntax:
<html>
<head>
{{ webassets_link('requirejs') }}
<script>
require(['some', 'dependencies'], function(some, dependencies) {
some(dependencies);
})
</script>
</head>
<!-- ... -->
</html>
Configuration¶
-
score.requirejs.
init
(confdict, tpl, webassets)[source]¶ Initializes this module acoording to the SCORE module initialization guidelines with the following configuration keys:
- config_file None
An optional javascript file containing the requirejs configuration. This file should only contain the configuration object itself, but the object does not have to adhere to a strict JSON syntax and may contain javascript functions. The following is a perfectly valid example for the referenced file’s content:
{ map: { 'some/newmodule': { 'foo': 'foo1.2' }, }, shim: { 'foo': { deps: ['bar'], exports: 'Foo', init: function (bar) { return this.Foo.noConflict(); } } } }
- passthrough_extensions []
- A list of additional file extensions that this module is allowed to pass
to browsers. If you want to pass mustache templates to the browser, for
example, you must provide the
mustache
extension in this list. - path.nodejs nodejs
- The path to the nodejs executable. This value is only relevant if
asset bundling is enabled in
score.webassets
.
Details¶
Client Interaction¶
The default behaviour of this module is to provide the requirejs library to the browser and to load all requested files asynchronously. The example provided in the quickstart section will render something like the following by default:
<html>
<head>
<script src="/_assets/requirejs/!require.js"></script>
<script src="/_assets/requirejs/!require-config.js"></script>
<script>
require(['some', 'dependencies'], function(some, dependencies) {
some(dependencies);
})
</script>
</head>
<!-- ... -->
</html>
The first script
tag will load the requirejs library, while the second tag
will load the javascript file containing the requirehs configuration. The
latter would look like the following, provided the file looks like the one in
the documentation of init()
:
requirejs.config({
map: {
'some/newmodule': {
'foo': 'foo1.2'
},
},
shim: {
'foo': {
deps: ['bar'],
exports: 'Foo',
init: function (bar) {
return this.Foo.noConflict();
}
}
}
});
The bundling behaviour of this module is configured via score.webassets
.
If the tpl.autobundle configuration of that module evaluates to True, the
result of the template will look differently:
<html>
<head>
<script src="/_assets/requirejs/__bundle_d9d396061cc84ccd__"></script>
<script>
require(['some', 'dependencies'], function(some, dependencies) {
some(dependencies);
})
</script>
</head>
<!-- ... -->
</html>
The bundle will consist of the minimal AMD implementation almond, the requirejs
configuration, all javascript files found in the the score.tpl
root
folder and all other files matching the additionally configured file
extensions.
API¶
-
score.requirejs.
init
(confdict, tpl, webassets)[source] Initializes this module acoording to the SCORE module initialization guidelines with the following configuration keys:
- config_file None
An optional javascript file containing the requirejs configuration. This file should only contain the configuration object itself, but the object does not have to adhere to a strict JSON syntax and may contain javascript functions. The following is a perfectly valid example for the referenced file’s content:
{ map: { 'some/newmodule': { 'foo': 'foo1.2' }, }, shim: { 'foo': { deps: ['bar'], exports: 'Foo', init: function (bar) { return this.Foo.noConflict(); } } } }
- passthrough_extensions []
- A list of additional file extensions that this module is allowed to pass
to browsers. If you want to pass mustache templates to the browser, for
example, you must provide the
mustache
extension in this list. - path.nodejs nodejs
- The path to the nodejs executable. This value is only relevant if
asset bundling is enabled in
score.webassets
.
-
class
score.requirejs.
ConfiguredRequirejsModule
[source]¶ This module’s
configuration class
.-
score_webassets_proxy
()[source]¶ Provides the webassets proxy.
-