• Stars
    star
    171
  • Rank 215,017 (Top 5 %)
  • Language
    JavaScript
  • Created over 7 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

code splitting as a component

react-modules

[work in progress]

npm install react-modules babel-template --save

code splitting as a component

import { Modules } from 'react-modules'

<Modules   
  load={require('./App.js')}>{ 
    // or arrays, or objects, whatevs
    App => App ? 
      <div><App /></div> : 
      <span>loading...</span>
}</Modules>
  • isomorphic / SSR friendly
  • transpiles to webpack-friendly split points with a plugin(react-modules/babel)
  • with helpers to preserve server-rendered html until module loads
  • leverage the structure of your app to efficiently split/load your javascript bundles

api

<Modules load={[require('A'), require('B'), {c: require('C')}]}>{
  ([A, B { c:C }]) => {...}
}</Modules>
  • load={reqs} - return the required modules with require. with the plugin, this will be converted to webpack code split points.
  • onError={fn} - catch errors
  • include={bool} - bypasses the code split
  • defer={bool} - loads the scripts only in the trasnpiled version
  • chunkName={str} - optional, acts as third argument to the backing require.ensure() call for named chunks
  • entry={name} - (experimental) include chunk into name entry. works in tandem with extractEntries() (TODO - accept multiple entries)

html persistence helpers

a set of helpers to preserve server/static-rendered html, until its 'parent' module loads. this is useful when the component is heavy, but you still want to show prerendered html while the chunk loads

  • preserve(id, DOMelement) : DOMelement
  • preserved(id) : DOMelement

example -

<Module load={require('./a').default}>{
  A => A ? preserve('myhtml', <div><App/></div>): // on SSR, this will generate html
    preserved('myhtml') || // on browser, use the cached html, until the module loads up
    <span>loading...</span> // if neither available, show loading state
}</Module>

Use sparingly! This will probably break react's checksum algo, but that's the tradeoff you'll need for this behavior.

NB: to prime the cache, import and call hydrate() right before you call ReactDOM.render().

plugin

  • react-modules/babel - wraps Modules components' load props with require.ensure boilerplate, generating code splits

extractEntries

  • extractEntries(filepath) (experimental) - statically analyze module and generate webpack entries

extractResourceMap

  • extractResourceMap(filepath) (experimental) - statically analyze an app and generate urlpattern -> entries map. works in tandem with react-router@4.

todo

  • docs
  • tests
  • custom <Match/> component that accepts entry/load
  • express helper/middleware to serve bundles
  • hmr compat
  • arbit file types / webpack loader compat
  • browserify compat
  • react-native

More Repositories

1

glamor

inline css for react et al
JavaScript
3,659
star
2

markdown-in-js

inline markdown for react/jsx
JavaScript
788
star
3

react-act-examples

Notes and examples on ReactTestUtils.act(...)
JavaScript
517
star
4

glam

crazy good css in your js
JavaScript
504
star
5

css-suspense

css loading for react
JavaScript
310
star
6

rakt

fast websites, by default
JavaScript
292
star
7

ratpack

ready. set. go!
JavaScript
198
star
8

freezus

magic component for transitions between screens
JavaScript
188
star
9

bs-nice

css-in-reason
OCaml
182
star
10

react-springs

react+rebound
JavaScript
91
star
11

react-tpl

abusing the platform
JavaScript
81
star
12

favre

jsx -> favicon
JavaScript
75
star
13

react-lazy-ssr-workers

react 18's streams running on cloudflare workers
JavaScript
67
star
14

react-redux-saga

react components for redux-saga
JavaScript
67
star
15

disto

mildly opinionated flux
JavaScript
65
star
16

react-ease

animations for react
JavaScript
53
star
17

glamor-stream

streaming inline glamor for your html
JavaScript
50
star
18

esjest-transform

A fast jest transform
JavaScript
45
star
19

y-workers

A Yjs backend on Cloudflare Workers
CSS
36
star
20

react-state

localized react state component
JavaScript
34
star
21

es-grid-kiss

es6 tagged literals + css grids
JavaScript
33
star
22

jsxn

jsx notation for json trees
JavaScript
32
star
23

require.import

sync-friendly code splits for webpack
JavaScript
26
star
24

react-superagent

universal ajax as a react component
JavaScript
26
star
25

react-loadscript

script tag as a react component
JavaScript
25
star
26

kv

a fast, immutable key-value store
JavaScript
24
star
27

routah

yet another router for react
JavaScript
22
star
28

iso-gol

conway's game of life, projected onto isometric 3d space in css
JavaScript
21
star
29

vite-plugin-react-jsx

A Vite plugin that enhances jsx transformation for React
TypeScript
18
star
30

glamor-inline

inlined css in your html
JavaScript
15
star
31

hotrod

JavaScript
12
star
32

babel-macros

macros for babel. I think.
12
star
33

react-router-modules

react-modules + react-router + ๐ŸŒˆ
JavaScript
12
star
34

pretty.fly

yet another async thing
JavaScript
12
star
35

proposal-error-assert

Error.assert() proposal for ECMAScript
TypeScript
11
star
36

oia

yet another lisp that compiles to javascript
JavaScript
9
star
37

xen

jsx+generators+p5.js
JavaScript
9
star
38

react-animated-web-bootleg

JavaScript
9
star
39

asyncstorage-mock

a mock for react-native's asyncstorage api. useful for testing.
JavaScript
9
star
40

falcro

falcor + react. hype!
JavaScript
7
star
41

built-devtools

chrome's devtools frontend, built.
JavaScript
7
star
42

react-debounce

debounce as a component
JavaScript
7
star
43

itree

trees with immutable.js
JavaScript
7
star
44

css-in-js-workshop

css, in your js, in your head, in your heart
JavaScript
6
star
45

max-payge

for max, because he asked
JavaScript
6
star
46

threepointone

VALUE
JavaScript
5
star
47

vite-jest

A configuration for runing jest tests inside vite
TypeScript
5
star
48

react-timing

timing as a component
JavaScript
4
star
49

twain

dynamic tweening engine
JavaScript
4
star
50

dahi

kefir, for js-csp
HTML
4
star
51

react-act-example

For Jason - https://twitter.com/CarrickJason/status/1171156605234077696
JavaScript
4
star
52

myxtape

content management systems for the new world
JavaScript
4
star
53

genno

async transforms / flow control with js-csp
JavaScript
3
star
54

riki

evil markup for documents
JavaScript
3
star
55

k

build systems, revisited
JavaScript
3
star
56

disto-example

disto examples, with hot loading of stores/views
CSS
3
star
57

prpl-with-react-example

whatevs dawg
JavaScript
2
star
58

shuffle

do the dom shuffle
JavaScript
2
star
59

progress

progress bar, alรก youtube
JavaScript
2
star
60

react-metronome

tick-tock as a component
CSS
2
star
61

bus

global event bus
JavaScript
2
star
62

vure

2
star
63

disto-hot-loader

hot load disto/flux stores
JavaScript
2
star
64

fn

tiny lib of functional helpers for personal projects
JavaScript
2
star
65

traced

JavaScript
2
star
66

times

functional times/map.
JavaScript
1
star
67

sandbox

sandboxed modules, ala YUI
JavaScript
1
star
68

iso

isometric math helpers
JavaScript
1
star
69

rust_project

Rust
1
star
70

game-of-life

generic game of life algorithm implementation in javascript
JavaScript
1
star
71

braid

experiments in clojurescript
JavaScript
1
star
72

lepton-labs-multiplayer

TypeScript
1
star
73

iso-grid

JavaScript
1
star
74

beam

funky get/set styles. WORK IN PROGRESS.
JavaScript
1
star
75

glamor-perf

HTML
1
star
76

async-act-test-21-11

Created with CodeSandbox
JavaScript
1
star
77

react-redux-optimist

react bindings for redux-optimist
JavaScript
1
star
78

zoui

HTML
1
star
79

Sangam

Static asset package generation and management
JavaScript
1
star
80

native-markup

JavaScript
1
star
81

scripts

useful (to me)
Ruby
1
star
82

oiarepl

a repl for oia
JavaScript
1
star
83

claw

css transforms without the heartache
JavaScript
1
star