RequireJS experts - your help is needed

RequireJS experts - your help is needed

allanallan Posts: 62,957Questions: 1Answers: 10,359 Site admin

I'm going to abuse my own forum and ask for help myself... :-).

I'm trying to get DataTables and all of its extensions ready for use with RequireJS and will publish documentation on that topic when it is ready. The JS part is simple enough, what I'm stumbling with is the styling aspect. Including DataTables without its styling components is fairly redundant, so adding styling information seems to be the sensible thing to do. Making it a little more complicated as well is the fact that some extensions require the core JS + styling JS and CSS, while some others only require the core JS and CSS.

I know that CSS is not supported by the RequireJS core, but I was hoping to use the require-css plug-in. That works well, but I can't find a way to have a module name include both the JS and CSS.

I found that the config.paths option for a module could specify multiple files in an array, so I tried:

        'datatables.net-bs': [
            'require-css!//nightly.datatables.net/css/dataTables.bootstrap.min',
            '//nightly.datatables.net/js/dataTables.bootstrap.min',
        ]

But the plug-ins operate on the module name, not the path. I had a look at the plug-ins API but can't see an option to add a plug-in at that point (unless anyone knows better)?

If that isn't the best approach, can anyone suggest what is a better one?

I basically want to be able to do something like this:

require( ['jquery', 'bootstrap', 'datatables.net-bs'], function ($, dt) {
    $('#myTable').DataTable();
} );

where datatables.net-bs will load the Bootstrap integration for DataTables (CSS and JS).

I could have the developer require both independently as different modules, but I can't see why you would ever want one without the other since they are interdependent and it would make their require line really verbose (particularly if they loaded a couple of the extensions and include one of the styling libraries).

This is what I have tried: http://jsfiddle.net/coaqsjkv/ - note that the CSS "plug-in" is not resolved at the path level giving a 404.

Anyone any ideas?

Regards,
Allan

Answers

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75

    I actually ran into an issue similar to this, any support I requested usually ended in "Don't just RequireJS, the benefits aren't worth it, just combine and minify all your JS/CSS files and load them at once"

    Id still like to try it out later though.

    /subscribed

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75

    @allan, did you ever find a solution for this? Just curious

  • allanallan Posts: 62,957Questions: 1Answers: 10,359 Site admin

    Not yet. To be honest I've not had time to look into it any further.

    Allan

This discussion has been closed.