Skip to content

Instantly share code, notes, and snippets.

@mohokh67
Last active March 6, 2019 12:49
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohokh67/f4009edfb58d92757483f9dc621d0289 to your computer and use it in GitHub Desktop.
Save mohokh67/f4009edfb58d92757483f9dc621d0289 to your computer and use it in GitHub Desktop.
Deploy single page app with react to zeit/now

Deploy single page app with react to zeit/now

After installing these two packages as we need them for deploy:

npm i now -g
npm i serve

follow these steps:

Step 1:

In package.json change the script part to this:

"scripts": {
  ...
  "start": "serve --single ./build",
  "dev": "react-scripts start",
  "build": "react-scripts build",
  "now-build": "npm run build && mv build dist",
  ...
 },

You also need to add serve package as we need it for start script.

Step 2:

Then add a new file now.json next to the root directory of your application.

{
 "version": 2,
 "name": "name-of-your-application",
 "builds": [{ "src": "package.json", "use": "@now/static-build" }],
 "routes": [
  { "src": "^/static/(.*)", "dest": "/static/$1" },
  { "src": "^/images/(.*)", "dest": "/images/$1" },
  { "src": ".*", "dest": "/index.html" }
 ]
}

Step 3:

Finally run the now command and DONE!

More info Here

@KarenCodes
Copy link

Thank you! This got Now working for me.

@waverly
Copy link

waverly commented Mar 4, 2019

@mohokh67 is this just for the frontend ? I'm trying to deploy my graphql yoga server to now without lucky

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment