Skip to content

Instantly share code, notes, and snippets.

View developit's full-sized avatar
🦊
write, the codes

Jason Miller developit

🦊
write, the codes
View GitHub Profile
@developit
developit / esmodules-polyfill.js
Last active November 15, 2020 21:19
polyfill ES2018 standard library stuff for ES Modules supporting browsers (Edge 16+, Firefox 60+, Chrome 61+, Safari 10.1+)
if (!('trimStart' in String.prototype)) String.prototype.trimStart = String.prototype.trimLeft;
if (!('trimEnd' in String.prototype)) String.prototype.trimEnd = String.prototype.trimRight;
if (!('forEach' in NodeList.prototype)) NodeList.prototype.forEach = [].forEach;
if (!('description' in Symbol.prototype)) {
Object.defineProperty(Symbol.prototype, 'description', {
get() { return /\((.+)\)/.exec(this)[1] }
});
}
@developit
developit / *babel-plugin-dynamic-import-polyfill.md
Created November 12, 2019 19:57
babel-plugin-dynamic-import-polyfill

[native-url] webpack demonstration

Normal Build: 13.4 kB

With [native-url]: 5.95 kB

(less than half the size)

The result is functionally equivalent in Node 7+ and all modern browsers (Chrome 61+, Firefox 60+, Safari 10+, Edge 16+ and anything else with ES Modules support).

const Component = require('preact/compat').Component;
const AUTOBIND_BLACKLIST = {
constructor: 1,
render: 1,
shouldComponentUpdate: 1,
componentWillReceiveProps: 1,
componentWillUpdate: 1,
componentDidUpdate: 1,
componentWillMount: 1,
import { h, options } from 'preact';
const X = 'props' in h('a');
export const getProps = X ? vnode => vnode.props : vnode => vnode.attributes;
export const setProps = X
? (vnode, props) => { vnode.props = props; }
: (vnode, props) => { vnode.attributes = props; };
package-lock.json
node_modules

optimize-css-assets-webpack-plugin-simple

It's literally the original plugin, just bundled up in a way that excludes SVGO. Instead of 10.6mb, it's 184kb and one file.

cssnano-preset-simple

This is cssnano-preset-default, but without SVGO. It's a fraction of the size on disk if you're looking to avoid the 10mb footprint.

cssnano-preset-simple

This is cssnano-preset-default, but without SVGO. It's a fraction of the size on disk if you're looking to avoid the 10mb footprint.

Combines all bare imports (npm module imports) into a single packd-es import.

Input:

import { h, render } from 'preact@next';
import { useState } from 'preact@next/hooks';
import { html } from 'htm/preact';
render(h(() => html`<a />`), document.body);