Skip to content

Instantly share code, notes, and snippets.

@fongandrew
fongandrew / vite-plugin-purgecss.ts
Created December 14, 2024 19:58
Vite plugin for PurgeCSS
/**
* A custom Vite plugin for PurgeCSS. The official one and other community plugins
* floating around seem to operate on only one CSS file at a time. When inspecting
* where a CSS class is used, we may need to consider all the JS and HTML files in
* the bundle.
*/
import { PurgeCSS, type UserDefinedOptions as PurgeCSSOptions } from 'purgecss';
import { type Plugin } from 'vite';
interface VitePurgeCSSOptions extends Omit<PurgeCSSOptions, 'content' | 'css'> {
@fongandrew
fongandrew / Terrible.js
Created January 10, 2020 20:37
For funsies
// npm install if
const If = require('if');
const f = (c, t, f) => If(c).Then(t).Else(f);
@fongandrew
fongandrew / react-bind.md
Last active January 14, 2024 16:02
Explaining why we bind things in React

Start With This

Before getting to React, it's helpful to know what this does generally in Javascript. Take the following snippet of code. It's written in ES6 but the principles for this predate ES6.

class Dog {
  constructor() {