How can RequireJS paths and require-css could be combined?

I’m using RequireJS and require-css with CDN URLs and it works well but I want to be able to define local fallbacks for my CSS dependencies and do something like this:

require.config( {
    paths: {
        'css!library-name': [ '<CDN_URL>', '<LOCAL_URL>' ]
    },
    map: {
        '*': {
            'css': '//cdn.jsdelivr.net/npm/require-css@0.1.10/css.min.js'
        }
    }
} );

require( [ 'css!library-name' ], function(){
    // ...
} );

I’ve searched and found no examples/guidance on how to do this. Any help would be appreciated.

Answer

I tested this and is working for me:

require.config( {
    paths: {
        // Also have a fallback for require-css itself
        'require-css': [ '//cdn.jsdelivr.net/npm/require-css@0.1.10/css', '../node_modules/require-css/css' ]
        'library-name-css': [ '<CDN_URL>', '<LOCAL_URL>' ]
    }
} );
require( [ 'require-css!library-name-css' ], function(){
    // ...
} );

Hope it helps someone. Note that working with fallbacks means you have to download the files locally (In this case I’m accomplishing by it using NPM)

Source: stackoverflow
The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .