I accidentally a Node.js command line tool that takes an HTML file with an internal stylesheet, purges the stylesheet from unused selectors in the surrounding HTML, minifies it, then places it back into the <style>
tags.
https://jeffkreeftmeijer.com/nodejs-purge-minify-css/