Skip to content

Instantly share code, notes, and snippets.

@intrnl
Created August 26, 2020 10:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save intrnl/5880fc4f3420767d4db3e74a2cab90db to your computer and use it in GitHub Desktop.
Save intrnl/5880fc4f3420767d4db3e74a2cab90db to your computer and use it in GitHub Desktop.
CSS modules namespace import
// 249 bytes
var o={helloWorld:"hello-world-123",fooBar:"foo-bar-245",barBaz:"bar-baz-934"};let l=Object.assign(document.createElement("div"),{textContent:"Hello world!",className:[o.helloWorld,o.helloWorld,o.fooBar,o.barBaz].join(" ")});document.body.append(l);
// 178 bytes
let e="hello-world-123",o=Object.assign(document.createElement("div"),{textContent:"Hello world!",className:[e,e,"foo-bar-245","bar-baz-934"].join(" ")});document.body.append(o);
// style.module.css
export default {
helloWorld: 'hello-world-123',
fooBar: 'foo-bar-245',
barBaz: 'bar-baz-934',
};
// index.js
import css from './style.module.css';
let el = Object.assign(document.createElement('div'), {
textContent: 'Hello world!',
className: [css.helloWorld, css.helloWorld, css.fooBar, css.barBaz].join(' '),
});
document.body.append(el);
// style.module.css
export let helloWorld = 'hello-world-123';
export let fooBar = 'foo-bar-245';
export let barBaz = 'bar-baz-934';
// index.js
import * as css from './style.module.css';
let el = Object.assign(document.createElement('div'), {
textContent: 'Hello world!',
className: [css.helloWorld, css.helloWorld, css.fooBar, css.barBaz].join(' '),
});
document.body.append(el);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment