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

inline-loader for webpack

Point this loader at an empty file, and it'll let you supply fake contents for that file.

import one from 'inline-loader?filenam=one.js&code=export default 1!./empty.js';

console.log(one)  // 1

Preact + Material-UI example

Preact is a fast 3kB alternative to React with the same modern API.

This example uses shows how to use Material UI 4 with Preact X and Preact CLI 3.

How to use

git clone blah preact-mui
.evaluateTypeof()
.evaluate()
.evaluateIdentifier()
.evaluateDefinedIdentifier()
.evaluateCallExpressionMember()
.statement(statement)
.statementIf(statement)
.label()
.import(statement,source)
.importSpecifier(statement,source,exportName,identifierName)

gzip-sizes

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

Usage

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

Options:

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.

export function Promise(initiator) {
var value;
var error;
var state = 0;
initiator(v => {
value = v;
state = 1;
q.forEach(this._with);
}, e => {
error = e;
@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.

/** 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) {
export default code => code.replace(/(?:[\s\t]+\/\*[\s\S]*?\*\/[\s\t]*|\s*(\n)\s*\/\/.*(?:\n\s*\/\/.*)*)/g, '$1')
# 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