Skip to content

Commit

Permalink
Setup deployment for examples using monorepo config for Now.
Browse files Browse the repository at this point in the history
  • Loading branch information
ghengeveld committed Jul 31, 2019
1 parent 30c601c commit 889fd8a
Show file tree
Hide file tree
Showing 18 changed files with 403 additions and 656 deletions.
4 changes: 4 additions & 0 deletions examples/basic-fetch/README.md
@@ -1,3 +1,7 @@
# Basic fetch with React Async

This demonstrates a very simple HTTP GET using `fetch`, wrapped with React Async.

<a href="https://react-async.ghengeveld.now.sh/examples/basic-fetch">
<img src="https://img.shields.io/badge/live-demo-blue.svg" alt="live demo">
</a>
3 changes: 2 additions & 1 deletion examples/basic-fetch/package.json
Expand Up @@ -2,6 +2,7 @@
"name": "basic-fetch-example",
"version": "1.0.1",
"private": true,
"homepage": "https://react-async.ghengeveld.now.sh/examples/basic-fetch",
"scripts": {
"postinstall": "relative-deps",
"prestart": "relative-deps",
Expand All @@ -10,7 +11,7 @@
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"now-build": "npm run build && mv build dist"
"now-build": "SKIP_PREFLIGHT_CHECK=true react-scripts build"
},
"dependencies": {
"react": "^16.8.6",
Expand Down
4 changes: 4 additions & 0 deletions examples/basic-hook/README.md
@@ -1,3 +1,7 @@
# Basic fetch with useAsync hook

This demonstrates how to use the `useAsync` hook.

<a href="https://react-async.ghengeveld.now.sh/examples/basic-hook">
<img src="https://img.shields.io/badge/live-demo-blue.svg" alt="live demo">
</a>
3 changes: 2 additions & 1 deletion examples/basic-hook/package.json
Expand Up @@ -2,6 +2,7 @@
"name": "basic-hook-example",
"version": "1.0.2",
"private": true,
"homepage": "https://react-async.ghengeveld.now.sh/examples/basic-hook",
"scripts": {
"postinstall": "relative-deps",
"prestart": "relative-deps",
Expand All @@ -10,7 +11,7 @@
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"now-build": "npm run build && mv build dist"
"now-build": "SKIP_PREFLIGHT_CHECK=true react-scripts build"
},
"dependencies": {
"react": "^16.8.6",
Expand Down
4 changes: 4 additions & 0 deletions examples/custom-instance/README.md
@@ -1,3 +1,7 @@
# Custom React Async instance

Demonstrates how to use a preconfigured React Async instance.

<a href="https://react-async.ghengeveld.now.sh/examples/custom-instance">
<img src="https://img.shields.io/badge/live-demo-blue.svg" alt="live demo">
</a>
3 changes: 2 additions & 1 deletion examples/custom-instance/package.json
Expand Up @@ -2,6 +2,7 @@
"name": "custom-instance-example",
"version": "1.0.1",
"private": true,
"homepage": "https://react-async.ghengeveld.now.sh/examples/custom-instance",
"scripts": {
"postinstall": "relative-deps",
"prestart": "relative-deps",
Expand All @@ -10,7 +11,7 @@
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"now-build": "npm run build && mv build dist"
"now-build": "SKIP_PREFLIGHT_CHECK=true react-scripts build"
},
"dependencies": {
"react": "^16.8.6",
Expand Down
4 changes: 4 additions & 0 deletions examples/movie-app/README.md
Expand Up @@ -2,3 +2,7 @@

This is a rebuild of the [React Suspense IO demo](https://reactjs.org/blog/2018/03/01/sneak-peek-beyond-react-16.html)
by Dan Abramov at JSConf Iceland 2018, using React Async instead of Suspense.

<a href="https://react-async.ghengeveld.now.sh/examples/movie-app">
<img src="https://img.shields.io/badge/live-demo-blue.svg" alt="live demo">
</a>
3 changes: 2 additions & 1 deletion examples/movie-app/package.json
Expand Up @@ -2,6 +2,7 @@
"name": "movie-app-example",
"version": "1.0.2",
"private": true,
"homepage": "https://react-async.ghengeveld.now.sh/examples/movie-app",
"scripts": {
"postinstall": "relative-deps",
"prestart": "relative-deps",
Expand All @@ -10,7 +11,7 @@
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"now-build": "npm run build && mv build dist"
"now-build": "SKIP_PREFLIGHT_CHECK=true react-scripts build"
},
"dependencies": {
"react": "^16.8.6",
Expand Down
4 changes: 4 additions & 0 deletions examples/with-abortcontroller/README.md
@@ -1,3 +1,7 @@
# Abortable fetch with React Async

This demonstrates a very simple HTTP GET using `fetch`, which gets the AbortSignal passed in to actually abort the HTTP request when the promise is canceled.

<a href="https://react-async.ghengeveld.now.sh/examples/with-abortcontroller">
<img src="https://img.shields.io/badge/live-demo-blue.svg" alt="live demo">
</a>
3 changes: 2 additions & 1 deletion examples/with-abortcontroller/package.json
Expand Up @@ -2,6 +2,7 @@
"name": "with-abortcontroller-example",
"version": "1.0.1",
"private": true,
"homepage": "https://react-async.ghengeveld.now.sh/examples/with-abortcontroller",
"scripts": {
"postinstall": "relative-deps",
"prestart": "relative-deps",
Expand All @@ -10,7 +11,7 @@
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"now-build": "npm run build && mv build dist"
"now-build": "SKIP_PREFLIGHT_CHECK=true react-scripts build"
},
"dependencies": {
"react": "^16.8.6",
Expand Down
7 changes: 7 additions & 0 deletions examples/with-nextjs/README.md
@@ -0,0 +1,7 @@
# React Async with Next.js

This demonstrates how React Async integrates with Next.js.

<a href="https://react-async.ghengeveld.now.sh/examples/with-nextjs">
<img src="https://img.shields.io/badge/live-demo-blue.svg" alt="live demo">
</a>
4 changes: 4 additions & 0 deletions examples/with-nextjs/next.config.js
@@ -0,0 +1,4 @@
module.exports = {
target: "serverless",
assetPrefix: "/examples/with-nextjs",
}
5 changes: 3 additions & 2 deletions examples/with-nextjs/package.json
Expand Up @@ -11,11 +11,12 @@
"pretest": "relative-deps",
"dev": "next",
"build": "next build",
"start": "next start"
"start": "next start",
"now-build": "next build"
},
"dependencies": {
"isomorphic-fetch": "^2.2.1",
"next": "^8.0.3",
"next": "^9.0.2",
"react": "^16.8.6",
"react-async": "^7.0.5",
"react-async-devtools": "^1.0.3",
Expand Down
Expand Up @@ -3,7 +3,7 @@ import Async from "react-async"
import DevTools from "react-async-devtools"
import fetch from "isomorphic-fetch"
import Link from "next/link"
import { withRouter } from "next/router"
import Router, { withRouter } from "next/router"

const loadUser = ({ userId = 1 }) =>
fetch(`https://reqres.in/api/users/${userId}`)
Expand All @@ -19,7 +19,8 @@ class Hello extends React.Component {

render() {
const { data, router } = this.props
const { userId = 1 } = router.query
const { pathname, query } = router
const userId = parseInt(query.userId, 10) || 1
return (
<>
{process.browser && <DevTools />}
Expand All @@ -41,12 +42,12 @@ class Hello extends React.Component {
</p>
<p>
{userId > 1 && (
<Link href={`?userId=${userId - 1}`}>
<Link href={`${pathname}?userId=${userId - 1}`}>
<a>Prev</a>
</Link>
)}{" "}
{userId < 12 && (
<Link href={`?userId=${data.id + 1}`}>
<Link href={`${pathname}?userId=${userId + 1}`}>
<a>Next</a>
</Link>
)}
Expand Down
47 changes: 5 additions & 42 deletions examples/with-typescript/README.md
@@ -1,44 +1,7 @@
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
# Using React Async with TypeScript

## Available Scripts
This demonstrates how React Async integrates with TypeScript.

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.<br>
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.<br>
You will also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.<br>
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.<br>
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.<br>
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).
<a href="https://react-async.ghengeveld.now.sh/examples/with-typescript">
<img src="https://img.shields.io/badge/live-demo-blue.svg" alt="live demo">
</a>
4 changes: 3 additions & 1 deletion examples/with-typescript/package.json
Expand Up @@ -2,14 +2,16 @@
"name": "with-typescript-example",
"version": "1.0.2",
"private": true,
"homepage": "https://react-async.ghengeveld.now.sh/examples/with-typescript",
"scripts": {
"postinstall": "relative-deps",
"prestart": "relative-deps",
"prebuild": "relative-deps",
"pretest": "relative-deps",
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test"
"test": "react-scripts test",
"now-build": "SKIP_PREFLIGHT_CHECK=true react-scripts build"
},
"dependencies": {
"@types/node": "^12.0.8",
Expand Down
48 changes: 48 additions & 0 deletions now.json
@@ -0,0 +1,48 @@
{
"version": 2,
"name": "react-async",
"public": true,
"builds": [
{
"src": "examples/basic-fetch/package.json",
"use": "@now/static-build",
"config": { "distDir": "build" }
},
{
"src": "examples/basic-hook/package.json",
"use": "@now/static-build",
"config": { "distDir": "build" }
},
{
"src": "examples/custom-instance/package.json",
"use": "@now/static-build",
"config": { "distDir": "build" }
},
{
"src": "examples/movie-app/package.json",
"use": "@now/static-build",
"config": { "distDir": "build" }
},
{
"src": "examples/with-abortcontroller/package.json",
"use": "@now/static-build",
"config": { "distDir": "build" }
},
{
"src": "examples/with-typescript/package.json",
"use": "@now/static-build",
"config": { "distDir": "build" }
},
{
"src": "examples/with-nextjs/package.json",
"use": "@now/next"
}
],
"routes": [
{ "src": "/examples/with-nextjs/_next(.*)", "dest": "examples/with-nextjs/_next$1" },
{ "src": "/examples/with-nextjs/", "dest": "examples/with-nextjs/examples/with-nextjs" },
{ "src": "/examples/with-nextjs(.*)", "dest": "examples/with-nextjs/examples/with-nextjs$1" },
{ "src": "/examples/(.*)", "dest": "/examples/$1" },
{ "src": "(.*)", "dest": "/examples$1" }
]
}

0 comments on commit 889fd8a

Please sign in to comment.