-
-
Notifications
You must be signed in to change notification settings - Fork 365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Require CSS in the path #201
Comments
I would start by trying with local copies, for example using bower to forget about manually updating the dependencies. Since there isn't a way to know for sure when a CSS stylesheet is done loading, you're asking too much. Second, you might want to look at normalize.js to see how the plugin deals with protocol relative urls and fallback paths. Third, the deps property shouldn't be parallel to paths. At least the way I config my apps, deps is a property of each module under the shims config. |
Thanks for the reply.
My understanding of what this plug-in for requirejs does is exactly that - from the readme: "Allows the construction of scripts that can require CSS"
Thank you I will. I'm not sure how that will help with using
The requirejs docs state that the |
This one worked for me requirejs.config({
paths: {
"require-css": "//cdnjs.cloudflare.com/ajax/libs/require-css/0.1.8/css.min",
"jquery": "//code.jquery.com/jquery-2.1.4.min",
"bootstrap": "//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min",
"datatables.net": "//nightly.datatables.net/js/jquery.dataTables.min",
"datatables.net-bs-js": "//nightly.datatables.net/js/dataTables.bootstrap.min",
"datatables.net-bs-style": "//nightly.datatables.net/css/dataTables.bootstrap.min"
}
});
define([
"jquery",
"datatables.net",
"datatables.net-bs-js",
"require-css!bootstrap",
"require-css!datatables.net-bs-style"
], function (jQuery) {
jQuery(document).ready(function () {
jQuery('#myTable').DataTable();
});
}); |
Absolutely that works - but my question is - can it be shortened and made less verbose? I want As I noted in my original post, this is absolutely possible already, but I'm looking to see if @guybedford knows if there is a cleaner approach. |
Hi,
I'm wondering if it is possible to specify that a CSS file should be loaded using the
paths
require.config.paths
object? The reason for doing this would be to have a single dependency name that can load both CSS and JS components of a library with a single statement.For example - my DataTables library, when styled by Bootstrap needs:
Something like the following would be awesome (note that
datatables.net-bs
's Javascript willrequire('datatables.net')
to include the core library):The way I thought I might be able to set this up was something like:
But the
require-css!
will only work in the module names it would seem.When I try the above, requirejs just requests a file from the url
http://.../require-css!//nightly.datatables.net/css/dataTables.bootstrap.min.js
- so there is no parsing being done there.I should note that I know I could create a new module to that would itself add the two individual file dependencies - but that could end up being really verbose and confusing since the AMD loader in the DataTables files will do a
require(...)
of their dependencies such asdatatables.net
for DataTables core (and even more so when considering the plug-ins for DataTables).The text was updated successfully, but these errors were encountered: