Skip to content

Instantly share code, notes, and snippets.

View esr360's full-sized avatar
👽
Best CSS-in-JS solution of 2020?

Edmund esr360

👽
Best CSS-in-JS solution of 2020?
View GitHub Profile
@developit
developit / *constant-locals-loader.md
Last active February 4, 2022 17:15
Inline Webpack CSS Modules classNames, reducing bundle size. https://npm.im/constant-locals-loader

constant-locals-loader for Webpack

This loader optimizes the output of mini-css-extract-plugin and/or css-loader, entirely removing the potentially large CSS classname mappings normally inlined into your bundle when using CSS Modules.

Run npm install constant-locals-loader, then make these changes in your Webpack config:

module.exports = {
 module: {
@saitonakamura
saitonakamura / fixCircular.js
Last active October 27, 2021 03:29
Function that replace circular js object dependency with "[Circular]" so it can be consumed by JSON.stringify
// DISCLAIMER
// Original function was updated to a faster and es5-supporting version by @Quacky2200
var replaceCircular = function(val, cache) {
cache = cache || new WeakSet();
if (val && typeof(val) == 'object') {
if (cache.has(val)) return '[Circular]';

Proposal: Importable Constructable Stylesheets

We're getting Constructable Stylesheets. This seems like an intuitive value to obtain when importing CSS from JavaScript, since it's the DOM's representation of a Stylesheet:

import stylesheet from './style.css';
console.log(stylesheet);  // CSSStyleSheet

No such system is in place to allow this to work (see [whatwg/loader]), however frontend build tooling has congregated around this approach as a mechanism for bringing CSS assets into the JavaScript module graph. There are many benefits to be obtained from moving CSS into this graph, however the most important is that imported CSS can be attributed to the consuming JS Module. This allows it to be bundled, optimized, and potentially dead-code-eliminated leveraging static analysis performed on the surrounding module graph.

@fdaciuk
fdaciuk / app.js
Created October 10, 2018 14:33
React: setState onBlur
import React from 'react'
class App extends React.Component {
state = { cep: '' }
handleBlur = (e) => {
this.setState({ cep: e.target.value })
}
render () {
@glennreyes
glennreyes / webpack.config.js
Last active January 16, 2019 03:22
How to disable Code Splitting in webpack
module.exports = {
module: {
rules: [
{
test: /\.(js|jsx)$/,
loader: require.resolve('babel-loader'),
include: ['src'],
options: {
presets: [
'dynamic-import-node',
@tzi
tzi / component.scss
Last active September 3, 2017 15:03
Using a "next generation mixin" to generate themes in sass
// Passing arguments from a mixin to a content block
// Planned for Sass 4
// https://github.com/sass/sass/issues/871
// File: common.scss
$theme-colors: (
pink: #FF69B4,
orange: #FFA500,
);
@AbhishekGhosh
AbhishekGhosh / External link icon Base64 Data URI.MD
Last active October 15, 2021 21:50
External link icon Base64 Data URI
@gazoakley
gazoakley / noma.html
Last active May 17, 2016 15:55
NOMA Code Review
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Federation | NOMA</title>
</head>
<body style="font:normal 100% 'Courier', serif;">
<?php echo "We've got ambition"; ?>
<h1>Great Creative Workspace/Multiple Buildings</h1>
<!-- 1GB wifi speeds -->
@ethanve
ethanve / sass-includes-loader.js
Last active September 18, 2021 09:16
Custom Webpack loader that prepends a Sass import to each imported Sass file
/**
* Loader that automatically prepends a reference to sassIncludes in the Webpack configuration files
*/
import fs from 'fs';
import path from 'path';
import config from './config';
let fileFound = true;
@jimfb
jimfb / wrapper.js
Last active November 6, 2018 04:41
class MyWrapper {
return React.Children.only(this.props.children);
}
class MyLibraryComponent {
render() {
return <div><span><whatever><MyWrapper ref=...>{this.props.statelessComponentThatIWantToReference}</MyWrapper></whatever></span></div>;
}