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 / package.json
Created May 30, 2019 15:19
Support for string styles in Preact X: <div style="color: red;">
{
"name": "preact-string-styles",
"main": "preact-string-styles.js",
"module": "preact-string-styles.js",
"version": "0.1.0",
"homepage": "https://gist.github.com/developit/d55dc3c47dd1fe81d84f5ee0ab5bfc58"
}
<!DOCTYPE html>
<html>
<head>
<title>Demo: Treat Safari 11 and Prior as nomodule</title>
</head>
<body>
<script>
if (/Safari\/5/.test(navigator.userAgent)) {
var $fss = function () {
for (var i of document.scripts) {
const IS_SERVER = typeof window === 'undefined';
export function RenderOnServer(props) {
return IS_SERVER ? props.children : null;
}
export function RenderOnClient(props) {
return IS_SERVER ? null : return props.children;
}
# scaffold your project
npx preact-cli@rc create default my-app && cd my-app
# upgrade to Preact X
npm i -D preact-cli@rc && npm i preact@latest preact-router@latest preact-render-to-string@latest
npm rm preact-compat
export default code => code.replace(/(?:[\s\t]+\/\*[\s\S]*?\*\/[\s\t]*|\s*(\n)\s*\/\/.*(?:\n\s*\/\/.*)*)/g, '$1')
/** Converts destructured parameters with default values to non-shorthand syntax, fixing Edge 16 & 17. */
module.exports = (babel, options = {}) => {
const { types: t } = babel;
const isArrowParent = p => p.parentKey=='params' && p.parentPath && p.parentPath.isArrowFunctionExpression();
return {
name: "transform-edge-default-parameters",
visitor: {
AssignmentPattern(path) {
@developit
developit / nextjs-local-development.md
Last active November 7, 2019 03:26
Test a local copy of Next.js against apps

Given a directory structure like the following:

📂projects
  📂next    <-- your Next.js checkout
  📂demo-app

Here's how to build your local copy of Next.js. You'll want to do this every time you make a change to Next itself.

export function Promise(initiator) {
var value;
var error;
var state = 0;
initiator(v => {
value = v;
state = 1;
q.forEach(this._with);
}, e => {
error = e;

Modern Script Loading

Loading modern code for modern browsers while still supporting older browsers should be possible via module/nomodule:

<script type="module" src="/modern.js"></script>
<script nomodule src="/legacy.js"></script>

... however this results in over-fetching of scripts in Edge and Safari.

gzip-sizes

A tiny CLI tool to print the gzipped sizes of files matching a glob pattern.

Usage

gzip-sizes [...pattern] [options]

Options: