I'm working on a project using require.js and plan to optimize it using r.js. The optimization for javascript files is built in as part of the require configration automatically.
What I would like is to split the CSS into several different files, e.g. head.css, body.css, main.css, etc. When r.js runs, it should concatenate these into a single file. The HTML would have:
<link rel=stylesheet type=text/css href=css/main.css>
A problem is that during development, the files will still be split up. I'd like to keep them split and don't want to have to redo the optimization every time -- even if it can be done automatically.
I'd also like to be able to keep the HTML with just the one stylesheet reference even in development. What would be the optimal way to do this?
There are several possibilities that I can see, each with potential problems:
- Have
main.cssuse@importto include all other CSS files.- Not automatic -- have to edit
main.cssfor each file. That's not a big deal since the number of files will be relatively small and probably all known very early on. r.jsdoes not optimize this
- Not automatic -- have to edit
- Use
require-css- This seems to be geared more towards AMD loading of CSS -- I'd rather load all the CSS up front
- Same issues with automatic loading of CSS files as the other option
- Create my own script that calls
r.jswithout CSS optimization, concatenate all of the CSS files and minify appropriately.- I'm sure there's someone out there who has done this better than I will