Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit 6487b66

Browse files
committed
4.0.0
- removes Styled Components; adds [Emotion](https://emotion.sh/) CSS-in-JS - adds [MobX](https://mobx.js.org/) - adds local state to `src/data/state.ts` - adds server dehydration/client hydration of MobX state - adds `src/lib/mobx.ts`, with helper functions for dehydration and feeding state context to React via `<StateProvider>` - adds `<StateConsumer>`, which takes a function and passes it local state; automatically re-renders React children when state is mutated - replaces Apollo local state counter example queries, state and mutations, and replaces with an `increment()` function on state - moves Apollo to `src/lib`; removes redundant `src/apollo` - removes `src/queries` - removes `src/mutations` - replaces Styled Components global with Emotion's `<Global>` type - adds new multi-build Dockerfile; bumps Node to 11.8 - removes theming - adds `scripts()` to `src/lib/stats.ts`, for finding related `.js` files to bootstrap on initial HTML render (wip toward adding cached, per-request vendor files) - dumps a full stack trace to the console in the event of a server error on any route, instead of just the message, for easier debugging - refactors `src/views/ssr.tsx` component to produce a map of `<script>` tags instead of taking a `js` var - updates readme
1 parent 499c6cd commit 6487b66

File tree

23 files changed

+393
-451
lines changed

23 files changed

+393
-451
lines changed

Dockerfile

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
1-
FROM node:10.11-alpine
1+
FROM node:11.8.0-alpine AS builder
22

3+
# log most things
34
ENV NPM_CONFIG_LOGLEVEL notice
45

5-
# Install NPM packages
6-
WORKDIR /app
6+
# OS packages for compilation
7+
RUN apk add --no-cache python2 make g++
8+
9+
# install NPM packages
10+
WORKDIR /build
711
ADD package*.json ./
812
RUN npm i
13+
14+
# add source
915
ADD . .
1016

11-
# Build
17+
# build
1218
RUN npm run build
1319

14-
EXPOSE 3000
20+
########################
21+
22+
FROM node:11.8.0-alpine
23+
WORKDIR /app
24+
25+
# copy source + compiled `node_modules`
26+
COPY --from=builder /build .
1527

16-
CMD npm run production
28+
# by default, run in production mode
29+
CMD npm run production

README.md

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,50 +13,52 @@ https://reactql.org
1313

1414
- [React v16](https://facebook.github.io/react/) for UI.
1515
- [Apollo Client 2.0 (React)](http://dev.apollodata.com/react/) for connecting to GraphQL.
16-
- Fully typed [Styled Components v4](https://www.styled-components.com/), with inline `<style>` tag generation that contains only the CSS that needs to be rendered, and full theming.
16+
- [MobX](https://mobx.js.org/) for declarative, type-safe flux/store state management (automatically re-hydrated from the server.)
17+
- [Emotion](https://emotion.sh/) CSS-in-JS, with inline `<style>` tag generation that contains only the CSS that needs to be rendered.
1718
- [Sass](https://sass-lang.com/), [Less](http://lesscss.org/) and [PostCSS](https://postcss.org/) when importing `.css/.scss/.less` files.
1819
- [React Router 4](https://github.com/ReactTraining/react-router/tree/v4) for declarative browser + server routes.
19-
- [Apollo Link State](https://www.apollographql.com/docs/link/links/state.html) for local flux/store state management (automatically re-hydrated from the server.)
20+
2021
- Declarative/dynamic `<head>` section, using [react-helmet](https://github.com/nfl/react-helmet).
2122

2223
### Server-side rendering
2324

2425
- Built-in [Koa 2](http://koajs.com/) web server, with async/await routing.
2526
- Full route-aware server-side rendering (SSR) of initial HTML.
2627
- Universal building - both browser + Node.js web server compile down to static files, for fast server re-spawning.
27-
- Per-request GraphQL local state. Store state is dehydrated via SSR, and rehydrated automatically on the client.
28+
- Per-request GraphQL store. Store state is dehydrated via SSR, and rehydrated automatically on the client.
29+
- MobX for app-wide flux/store state, with a built-in `<StateConsumer>` for automatically re-rendering any React component that 'listens' to state and full client-side rehydration. Fully typed state!
2830
- Full page React via built-in SSR component - every byte of your HTML is React.
2931
- SSR in both development and production, even with hot-code reload.
3032

3133
### Real-time
3234

3335
- Hot code reloading; zero refresh, real-time updates in development.
3436
- Development web server that automatically sends patches on code changes, and restarts the built-in Web server for SSR renders that reflect what you'd see in production.
35-
- New in v3.5: WebSocket `subscription` query support for real-time data (just set `WS_SUBSCRIPTIONS=1` in [.env](.env))
37+
- WebSocket `subscription` query support for real-time data (just set `WS_SUBSCRIPTIONS=1` in [.env](.env))
3638

3739
### Code optimisation
3840

3941
- [Webpack v4](https://webpack.js.org/), with [tree shaking](https://webpack.js.org/guides/tree-shaking/) -- dead code paths are automatically eliminated.
4042
- Asynchronous code loading when `import()`'ing inside a function.
41-
- Aggressive code minification.
43+
- Automatic per-vendor chunk splitting/hashing, for aggressive caching (especially good behind a HTTP/2 proxy!)
44+
- Gzip/Brotli minification of static assets.
4245
- CSS code is combined, minified and optimised automatically - even if you use SASS, LESS and CSS together!
4346

4447
### Styles
4548

46-
- [Styled Components v4](https://www.styled-components.com/), for writing CSS styles inline and generating the minimal CSS required to properly render your components. Full type inference on themes, too.
49+
- [Emotion](https://emotion.sh/), for writing CSS styles inline and generating the minimal CSS required to properly render your components.
4750
- [PostCSS v7](http://postcss.org/) with [next-gen CSS](https://preset-env.cssdb.org/) and automatic vendor prefixing when importing `.css`, `.scss` or `.less` files.
4851
- [SASS](http://sass-lang.com) and [LESS](http://lesscss.org/) support (also parsed through PostCSS.)
4952
- Automatic vendor prefixing - write modern CSS, and let the compiler take care of browser compatibility.
5053
- Mix and match SASS, LESS and regular CSS - without conflicts!
5154
- CSS modules - your classes are hashed automatically, to avoid namespace conflicts.
52-
- Compatible with Foundation, Bootstrap, Material and more. Simply configure via a `.global.(css|scss|less)` import to preserve class names.
55+
- Compatible with Foundation, Bootstrap, Material UI and more. Simply configure via a `.global.(css|scss|less)` import to preserve class names.
5356

5457
### Production-ready
5558

5659
- Production bundling via `npm run production`, that generates optimised server and client code.
5760
- [Static compression](https://webpack.js.org/plugins/compression-webpack-plugin/) using the Gzip and [Brotli](https://opensource.googleblog.com/2015/09/introducing-brotli-new-compression.html) algorithms for the serving of static assets as pre-compressed `.gz` and `.br` files (your entire app's `main.js.bz` - including all dependencies - goes from 346kb -> 89kb!)
58-
- Automatic HTTP hardening against common attack vectors via [Koa Helmet](https://github.com/venables/koa-helmet) (highly configurable)
59-
- New in v3.5: Static bundling via `npm run static`. Easily deploy a client-only SPA to any static web host (Netlify, etc.)
61+
- Static bundling via `npm run static`. Don't need server-side rendering? No problem. Easily deploy a client-only SPA to any static web host (Netlify, etc.)
6062

6163
### Developer support
6264

@@ -68,8 +70,8 @@ https://reactql.org
6870
Grab and unpack the latest version, install all dependencies, and start a server:
6971

7072
```
71-
wget -qO- https://github.com/leebenson/reactql/archive/3.7.1.tar.gz | tar xvz
72-
cd reactql-3.7.1
73+
wget -qO- https://github.com/leebenson/reactql/archive/4.0.0.tar.gz | tar xvz
74+
cd reactql-4.0.0
7375
npm i
7476
npm start
7577
```
@@ -80,11 +82,11 @@ Your development server is now running on [http://localhost:3000](http://localho
8082

8183
Development mode offers a few useful features:
8284

83-
- Hot code reloading. Make a change anywhere in your code base (outside of the Webpack config), and changes will be pushed down the browser automatically - without page reloads. This happens for React, Styled Components, SASS - pretty much anything.
85+
- Hot code reloading. Make a change anywhere in your code base (outside of the Webpack config), and changes will be pushed down the browser automatically - without page reloads. This happens for React, Emotion, SASS - pretty much anything.
8486

85-
- Full source maps for Javascript and CSS
87+
- Full source maps for Javascript and CSS.
8688

87-
- Full server-side rendering, with automatic Koa web server restarting on code changes. This ensures the initial HTML render will always reflect your latest code changes
89+
- Full server-side rendering, with automatic Koa web server restarting on code changes. This ensures the initial HTML render will always reflect your latest code changes.
8890

8991
To get started, simply run:
9092

@@ -130,43 +132,37 @@ The important stuff is in [src](src).
130132

131133
Here's a quick run-through of each sub-folder and what you'll find in it:
132134

133-
- [src/components](src/components) - React components. Follow the import flow at [root.tsx](src/components/root.tsx) to figure out the component render chain. I've included an [example](src/components/example) component that shows off some Apollo GraphQL features, including incrementing a local counter and pulling top news stories from Hacker News (a live GraphQL server endpoint.)
135+
- [src/components](src/components) - React components. Follow the import flow at [root.tsx](src/components/root.tsx) to figure out the component render chain. I've included an [example](src/components/example) component that shows off some Apollo GraphQL and MobX features, including incrementing a local counter and pulling top news stories from Hacker News (a live GraphQL server endpoint.)
134136

135-
- [src/data](src/data) - Data used throughout your app. You'll find [routes.ts](src/data/routes.ts), which defines your React Router routes (currently, just the home page -- but you can easily extend this.)
137+
- [src/data](src/data) - Data used throughout your app. You'll find [routes.ts](src/data/routes.ts), which defines your React Router routes (currently, just the home page -- but you can easily extend this.) and [state.ts](src/data/state.ts), to show you how simple it is to define your own state data fields that, when modified, automatically re-render any 'observing' component.
136138

137139
- [src/entry](src/entry) - The client and server entry points, which call on [src/components/root.tsx](src/components/root.tsx) to isomorphically render the React chain in both environments.
138140

139-
- [src/global](src/global) - A good place for anything that's used through your entire app, like global styles. I've started you off with a [styles.ts](src/global/styles.ts) that sets globally inlined Styled Components CSS, as well as pulls in a global `.scss` file -- to show you how both types of CSS work.
140-
141-
- [src/graphql](src/graphql) - GraphQL initialisation goes here. There's an [apollo.ts](src/graphql/apollo.ts) which builds a universal Apollo Client and enables local state, and [state.ts](src/graphql/state.ts) which sets up default state (automatically rehydrated on the client) and some mutation handlers, for incrementing a local counter.
141+
- [src/global](src/global) - A good place for anything that's used through your entire app, like global styles. I've started you off with a [styles.ts](src/global/styles.ts) that sets globally inlined Emotion CSS, as well as pulls in a global `.scss` file -- to show you how both types of CSS work.
142142

143-
- [src/lib](src/lib) - Library functions to handle hot-code reloading, finding the right `main.js` / `main.css` in production (which is automatically hashed for versioning), Webpack stats and Styled Components.
143+
- [src/lib](src/lib) - Internal libraries/helpers. There's an [apollo.ts](src/lib/apollo.ts) which builds a universal Apollo Client, and [mobx.ts](src/graphql/mobx.ts) which sets up default state (automatically rehydrated on the client), for incrementing a local counter. Plus, functions to handle hot-code reloading, Webpack stats helpers (used by the server to automatically load the right `<script>` tags, and some internal stuff to help with hot-code reloading the server when code changes in developmnt.
144144

145-
- [src/mutations](src/mutations) - Your GraphQL mutations. Out-the-box, you'll find the query to increment the local state counter.
146-
147-
- [src/queries](src/queries) - Your GraphQL queries. There are two by default - one that grabs the local counter state, another that pulls the top stories from Hacker News to display in the example component.
145+
- [src/queries](src/queries) - Your GraphQL queries. There's just one by default - for pilling the top stories from Hacker News to display in the example component.
148146

149147
- [src/runner](src/runner) - Development and production runners that spawn the Webpack build process in each environment.
150148

151-
- [src/themes](src/themes) - A sample [interface](src/themes/interface.ts) type for defining a Styled Components theme, and a [default theme](src/themes/default.ts) that's used in the example component to add an orange hover to Hacker News links.
152-
153-
- [src/views](src/views) - View components that fall outside of the usual React component chain, for use on the server. In here, [ssr.tsx](src/views/ssr.tsx) takes care of rendering the root HTML that's sent down the wire to the client. Note this is also a React component - your whole app will render as React!
149+
- [src/views](src/views) - View components that fall outside of the usual React component chain, for use on the server. In here, [ssr.tsx](src/views/ssr.tsx) takes care of rendering the root HTML that's sent down the wire to the client. Note this is also a React component - your whole app will render as React! - and [static.html](src/views/static.html) serves as a template for rendering a client-side SPA. Update it as needed.
154150

155151
- [src/webpack](src/webpack) - The Webpack 4 configuration files that do the heavy lifting to transform our Typescript code, images and CSS into optimised and minified assets that wind up in the `dist` folder at the root. Handles both the client and server environments.
156152

157153
You'll also find some other useful goodies in the [root]()...
158154

159155
- [.env](.env) - Change your `GRAPHQL` server endpoint, and `WS_SUBSCRIPTIONS=1` for built-in WebSocket support.
160156

161-
- [.nvmrc](.nvmrc) - Specify your preferred Node.js version, for use with NVM and used by many continuous deployment tools. Defaults to v10.11
157+
- [.nvmrc](.nvmrc) - Specify your preferred Node.js version, for use with NVM and used by many continuous deployment tools. Defaults to v11.8.0
162158

163159
- [netlify.toml](netlify.toml) - Build instructions for fast [Netlify](https://www.netlify.com/) deployments. **Tip: To quickly deploy a demo ReactQL app, [click here](https://app.netlify.com/start/deploy?repository=https://github.com/leebenson/reactql).**
164160

165161
- [types](types) - Some basic types that allow you to import fonts, images, CSS/SASS/LESS files, and allow use of the global `SERVER` boolean in your IDE.
166162

167-
- Typescript configuration via [tsconfig.json](tsconfig.json) and [tslint.json](tslint.json)
163+
- Typescript configuration via [tsconfig.json](tsconfig.json)
168164

169-
- A sample [Dockerfile](Dockerfile) for quickly deploying your code base to production.
165+
- A sample multi-build [Dockerfile](Dockerfile) based on Node 11.8 and Alpine, for quickly deploying your code base to production.
170166

171167
# Follow @reactql for updates
172168

0 commit comments

Comments
 (0)