Hi Developers!
Jdatatables comes in a bunch of modules which are linked to each other by requireJS. Usualy these modules were delivered as a single datatables.net.js file with a structure like:
# Module datatables.net
define('datatables.net', ('jquery', ..
# Module datatables_select
define('datatables_select', (''datatables.net', 'jquery', ..)
# Module datatables_xxx
define('datatables_xxx', (''datatables.net', 'jquery', ..)
I have managed to to require the main module "datatables.net" from my JS code (a mockup pattern for encapsulate the whole datatables stuff) utilizing the plone resource registry by creating a resource for the datatables.net.js and datatables.net.css file. From my pattern I require datatables.net like:
require([
'jquery',
'pat-base',
'pat-registry',
'datatables.net',
], function ($, Base, Registry, Datatables) {
This works flawlessly and can be compiled via the build button in the plone ressource registry.
Now to my two questions:
-
Despite having the datatables.net.css file registered in the same ressource as the datatables.net.js file and the datatables.net.js is loaded correctly the css is not loaded automatically. To load the CSS I have to import it manually via the less file of my pattern.less file.
@import (inline) "@{inqbus_mailcenter_resources}datatables/datatables.net.css";
Is this the intended behavior of the resource registry? What am I doing wrong?
-
Despited having the datatables_select module (with the same requieredJS structure) in the same js file as the datatables.net and despite the JS code for the datatables_select module is available in the resulting resource bundle I cannot require this module
require([ 'jquery', 'pat-base', 'pat-registry', 'datatables.net', 'datatables_select', ], function ($, Base, Registry, Datatables, Datatables_select) {
If I try to compile this requirement the ressource registry looks unsuccessfull for a file "datatables_select.js" which is (no wonder) not available.
One obvious workaround would be to break up the datatables.net.js file into a bunch of files 'datatabels.net.js', 'datatables_select.js', and so on. Aside from having a lot of work I am quite sure that this behavior of the resource registry is not intended. After parsing the "datatables.net.js" file the requireJS machinery has seen the definition of the module "datatales_select". And therefore has enough information to find the URL to the module if it is required.
I am a big fan of modularism but in times the JS packages become larger every day the solution of putting each requiredJS definition in a single file cannot be the answer.
So what is the way to go here?