Generate css using EJS?

EJS renders dynamic HTML. That’s easy. But, I would like to render css as well. EJS doesn’t support rendering of css. Sure, there are some static options available. I would like to have a few elements in the css file be changeable, for example, colours. Some users would like a dark mode. I could simply have Node.js serve up two different css files depending on user setting, that would work, but then would need another CSS file for every possible option. I would like to embed JS inside a CSS file and have Node.JS render it in the exact same fashion it currently performs on HTML.

Why? Because, that’s the easiest solution. I don’t see a reason why EJS can’t be made to work in the same fashion on a CSS file, it’s not like the syntax is complex, and surely <%= %> and <% %> could be embedded into it?

Other alternatives would be generating the css file in straight JS without any embedding. That’s a possibility.

  • What about things like LESS or SCSS?

    – 

Leave a Comment