4 ms·
requirejs doesn't natively support css, but it has a pretty easy to use loader api so it'd be easy to add css support and in fact one already exists: https://gi
by dgoldstein0 9y ago
requirejs doesn't natively support css, but it has a pretty easy to use loader api so it'd be easy to add css support and in fact one already exists: https://github.com/guybedford/require-css https://github.com/guybedford/require-css
- emergie 9y agolib you linked is a bit crazy, it uses setInterval to guess when a css is properly loaded/applied and delays running dependent code imho this is sufficient: define('css', function () { return { load: function (name, parentRequire, onload, config) { console.log('loading css ' + name); const link = document.createElement('link'); link.type = 'text/css'; link.rel = 'stylesheet'; link.href = name + '.css'; document.getElementsByTagName('head')[0].appendChild(link); setTimeout(onload, 0); } }; }); usage: require(['lib/js/jquery-ui.min', 'css!lib/css/jquery-ui.min'], function () { // jquery-ui magic goes here });
- hdhzy 9y agoYou don't need to guess, you can check document.styleSheets if it contains your file. See: https://curiosity-driven.org/minimal-loader#plugins https://curiosity-driven.org/minimal-loader#plugins