4

I have a project that uses React and I would like to trim my CSS build file. React has no html files so I'm not sure how to get UnCSS working with React. Can I use React with UnCSS? If yes how would I proceed?

Jonathan de M.
  • 9,721
  • 8
  • 47
  • 72
  • 1
    UnCSS uses phantom.js, so in general: yes! my guess is, you only have to give UnCss the URL you visit when you open your react project in a browser. – jukempff Jul 20 '15 at 19:13

1 Answers1

0

As already commented it is possible to use React with uncss by supplying the urls to pages. However, there is an alternative way. React has a function renderToString which will return the output HTML as a string. you can write this to a file and pass the file to uncss for it to find all css selectors. Keep in mind that it won't detect classes added dynamically so those will have to be added manually in ignore property of options object passed to uncss. You can read more about it on uncss docs

Anton Kastritskiy
  • 1,248
  • 1
  • 11
  • 23