I am attempting to modify CSS as part of a Node JS build process, but most of what I can find online refers to doing this in the DOM with Javascript. Is it possible to read a file in Node and access the equivalent of document.stylesheet or the cssRules property or is this a DOM-only concept and I need to stick with string replacement to modify these CSS rules/properties?
For reference here is the browser-based answer to the problem I’m trying to solve: How do you read CSS rule values with JavaScript?
>Solution :
I think there’s nothing bad to manipulate CSS with DOM, use for that: https://www.npmjs.com/package/jsdom
For manipulate CSS directly you could parse it into AST:
https://www.npmjs.com/package/css-tree
CSSTree is a tool set for CSS: fast detailed parser (CSS → AST), walker (AST traversal), generator (AST → CSS) and lexer (validation and matching) based on specs and browser implementations. The main goal is to be efficient and W3C spec compliant, with focus on CSS analyzing and source-to-source transforming tasks.