Last active
December 27, 2016 12:03
-
-
Save jeffturcotte/9509721 to your computer and use it in GitHub Desktop.
RequireJS per page module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require.config({ | |
baseUrl: '/scripts/lib', | |
paths: { | |
app: '../app', | |
jquery: 'jquery-1.11.0', | |
handlebars: 'handlebars-v1.3.0', | |
ckeditorCore: 'ckeditor/ckeditor', | |
ckeditor: 'ckeditor/adapters/jquery' | |
}, | |
shim: { | |
ckeditor: { | |
deps: ['jquery', 'ckeditorCore'] | |
}, | |
handlebars: { | |
exports: 'Handlebars' | |
} | |
} | |
}); | |
// this following snippet reads the data-module attribute and requires it | |
require(['jquery'], function($) { | |
if (module = $('script[src$="require.js"]').data('module')) { | |
require([module]); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<title>{{ title|title }}</title> | |
<link rel="stylesheet" href="/styles/common.css" /> | |
<link rel="stylesheet" href="/styles/layout.css" /> | |
</head> | |
<body> | |
{{ include('header.html') }} | |
{% block content %} | |
{% endblock %} | |
{{ include('footer.html') }} | |
{# we set the script variable wherever we are rendering the template #} | |
{# and twig adds it to the data-module attr below #} | |
<script | |
data-module="{{ script }}" | |
data-main="/scripts/app.js" | |
src="/scripts/require.js"> | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment