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
import './style';
import { Component } from 'preact';
export default class App extends Component {
render() {
return (
<div>
<h1>Hello, World!</h1>
</div>
);

Module Worker polyfill for Chrome 61+

Chrome 61+ supports dynamic import() within Classic Workers. We can use this to polyfill Module Workers to a reasonable degree of accuracy.

The only trick is that we need to queue up any messages received while we wait for the module tree to load in the Worker, since Module Workers load the entire dependency graph before flushing messages queued during Worker instantiation.

This polyfill comes in two versions:

module-workers-polyfill-inline.js is a single-file polyfill, but creates Workers with an Opaque Origin. If you're only loading dependencies from absolute URLs and not relying on storage like IndexedDB, this option is fine.

import { wrap, expose } from 'https://unpkg.com/comlink@4.2.0/dist/esm/comlink.mjs';
export default name => wrap(new Worker(import.meta.url, { env:{name}, type:'module' }));
if (process.env.name && !self.document) {
const q = []; onmessage = q.push.bind(q);
import(process.env.name).then(expose).then(() => onmessage = q.map(dispatchEvent))
}

finally-polyfill

A tiny ~150-byte polyfill for Promise.prototype.finally.

Useful for browsers that support Promise but not the .finally() method.

Usage

npm install finally-polyfill

@developit
developit / material-ui-jsdelivr-cdn.htm
Created January 22, 2020 17:16 — forked from tomByrer/material-ui-jsdelivr-cdn.htm
React-MUI using jsDelivr CDN for in-browser hydration.
<!DOCTYPE html>
<html lang="en">
<head>
<title>My page</title>
<meta charset="utf-8" />
<meta name="viewport" content="minimum-scale=1, initial-scale=1, width=device-width" />
<script src="https://cdn.jsdelivr.net/combine/npm/react@16.12/umd/react.development.js,npm/react-dom@16.12/umd/react-dom.development.js,npm/@material-ui/core@4.8/umd/material-ui.development.js,npm/@babel/standalone@7.8/babel.min.js" crossorigin="anonymous"></script>
<!-- Seperate Links
src: https://github.com/mui-org/material-ui/blob/master/examples/cdn/index.html -->

babel-plugin-transform-mui-imports npm

A plugin to make authoring with MUI components efficient, both for humans and bundlers.

Here's why:

var t,e,n,r,o,u,i,l={},c=[],_=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord/i;function a(t,e){for(var n in e)t[n]=e[n];return t}function s(t){var e=t.parentNode;e&&e.removeChild(t)}function f(t,e,n){var r,o=arguments,u={};for(r in e)"key"!==r&&"ref"!==r&&(u[r]=e[r]);if(arguments.length>3)for(n=[n],r=3;r<arguments.length;r++)n.push(o[r]);if(null!=n&&(u.children=n),"function"==typeof t&&null!=t.defaultProps)for(r in t.defaultProps)void 0===u[r]&&(u[r]=t.defaultProps[r]);return p(t,u,e&&e.key,e&&e.ref)}function p(e,n,r,o){var u={type:e,props:n,key:r,ref:o,__k:null,__:null,__b:0,__e:null,__d:null,__c:null,constructor:void 0};return t.vnode&&t.vnode(u),u}function h(){return{}}function d(t){return t.children}function v(t,e){this.props=t,this.context=e}function m(t,e){if(null==e)return t.__?m(t.__,t.__.__k.indexOf(t)+1):null;for(var n;e<t.__k.length;e++)if(null!=(n=t.__k[e])&&null!=n.__e)return n.__e;return"function"==typeof t.type?m(t):null}function y(t){var e,n;if(null!=(t=t.__)&&null!=t.__c){for(t._

resolve(), with Conditional Export Maps

This is a version of the resolve module that is extended with support for Conditional Export Maps, including Package Exports as shipped in Node.

The resolve module powers module resolution in Webpack, Rollup and Browserify.

API

The module maintains the same API and functionality as the original resolve() module.

var s;
function supportsModuleWorkers() {
if (s==null) {
s = false;
try {
new Worker('data:,', Object.defineProperty({}, 'type', {
get() { s = true; }
})).terminate();
} catch (e) {}
}