Webpack and Browserify both offer CSS module plugins that will generate the necessary code
The task runs after you have written your CSS/SCSS/LESS
.base { color: deeppink; max-width: 42em; margin: 0 auto; }
._20WEds96_Ee1ra54-24ePy { color: deeppink; max-width: 42em; margin: 0 auto; }
import styles from './styles.css';
element.innerHTML = `<div class="${styles.base}">
CSS Modules are fun.
</div>`;
<div class="_20WEds96_Ee1ra54-24ePy">CSS Modules are fun.</div>
They are parsed into unique strings
:]
.base { composes: appearance from '../AnoherModule/styles.css'; }
:global(.clearfix::after) { content: ''; clear: both; display: table; }
const html = `
<div class="${styles.root}">
<img class="${styles.image}" src="${data.image}" />
<p class="${styles.description}">${data.description}</p>
</div> `;http://chrispearce.co/elephants-the-three-code-ilities-two-months-with-css-modules/
http://www.sitepoint.com/understanding-css-modules-methodology/
https://github.com/css-modules/webpack-demo