From 4cab5228a06cef0d79a27a9ace14fe6ef7f9e59b Mon Sep 17 00:00:00 2001 From: Thierry Charbonnel Date: Fri, 8 Dec 2017 21:17:04 -0500 Subject: [PATCH] Github gh-pages Example (#3383) * gh-page-exemple * add babelrc for gh-page exemple * Fix example (exemple in fr) * example fix typo * lint fix --- examples/gh-pages/.babelrc | 8 +++++ examples/gh-pages/.gitignore | 2 ++ examples/gh-pages/README.md | 57 ++++++++++++++++++++++++++++++++ examples/gh-pages/env-config.js | 5 +++ examples/gh-pages/next.config.js | 15 +++++++++ examples/gh-pages/package.json | 20 +++++++++++ examples/gh-pages/pages/about.js | 7 ++++ examples/gh-pages/pages/index.js | 4 +++ 8 files changed, 118 insertions(+) create mode 100644 examples/gh-pages/.babelrc create mode 100644 examples/gh-pages/.gitignore create mode 100644 examples/gh-pages/README.md create mode 100644 examples/gh-pages/env-config.js create mode 100644 examples/gh-pages/next.config.js create mode 100644 examples/gh-pages/package.json create mode 100644 examples/gh-pages/pages/about.js create mode 100644 examples/gh-pages/pages/index.js diff --git a/examples/gh-pages/.babelrc b/examples/gh-pages/.babelrc new file mode 100644 index 00000000..e1580ad7 --- /dev/null +++ b/examples/gh-pages/.babelrc @@ -0,0 +1,8 @@ +{ + "presets": [ + "next/babel" + ], + "plugins": [ + ["transform-define", "./env-config.js"] + ] +} diff --git a/examples/gh-pages/.gitignore b/examples/gh-pages/.gitignore new file mode 100644 index 00000000..b90a368f --- /dev/null +++ b/examples/gh-pages/.gitignore @@ -0,0 +1,2 @@ +node_modules +.next diff --git a/examples/gh-pages/README.md b/examples/gh-pages/README.md new file mode 100644 index 00000000..a9b040b2 --- /dev/null +++ b/examples/gh-pages/README.md @@ -0,0 +1,57 @@ +# gh-pages Hello World example + +## How to use + +### Download manually + +Download the example [or clone the repo](https://github.com/zeit/next.js): + +```bash +curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2 next.js-master/examples/gh-pages +cd gh-pages +``` + +Install it and run: + +```bash +npm install +npm run dev +``` + +Deploy it to github + +Edit ```env-config.js``` and replace ```'Next-gh-page-example'``` by your project name. + +Edit ```next.config.js``` and replace ```'Next-gh-page-example'``` by your project name. + +1. Create repository. +2. Link it to your github account. +3. Publish your master branch. + +```bash +npm run deploy +``` + +Test it: + +Reaplce 'github-user-name' and 'github-projet-name' + +```bash + +https://github-user-name.github.io/github-projet-name/ + +``` + +Example: + +```bash + +https://github.com/thierryc/Next-gh-page-example/ + +https://thierryc.github.io/Next-gh-page-example/ + +``` + +## The idea behind the example + +This example shows the most basic idea behind Next. We have 2 pages: `pages/index.js` and `pages/about.js`. The former responds to `/` requests and the latter to `/about`. Using `next/link` you can add hyperlinks between them with universal routing capabilities. diff --git a/examples/gh-pages/env-config.js b/examples/gh-pages/env-config.js new file mode 100644 index 00000000..9959cb5e --- /dev/null +++ b/examples/gh-pages/env-config.js @@ -0,0 +1,5 @@ +const prod = process.env.NODE_ENV === 'production' + +module.exports = { + 'process.env.BACKEND_URL': prod ? '/Next-gh-page-example' : '' +} diff --git a/examples/gh-pages/next.config.js b/examples/gh-pages/next.config.js new file mode 100644 index 00000000..24b25b8e --- /dev/null +++ b/examples/gh-pages/next.config.js @@ -0,0 +1,15 @@ +// This file is not going through babel transformation. +// So, we write it in vanilla JS +// (But you could use ES2015 features supported by your Node.js version) + +const debug = process.env.NODE_ENV !== 'production' + +module.exports = { + exportPathMap: function () { + return { + '/': { page: '/' }, + '/about': { page: '/about' } + } + }, + assetPrefix: !debug ? '/Next-gh-page-example/' : '' +} diff --git a/examples/gh-pages/package.json b/examples/gh-pages/package.json new file mode 100644 index 00000000..3942c46d --- /dev/null +++ b/examples/gh-pages/package.json @@ -0,0 +1,20 @@ +{ + "name": "gh-pages", + "version": "1.0.0", + "scripts": { + "dev": "next", + "build": "next build", + "start": "next start", + "export": "next export", + "deploy": "rm -rf node_modules/.cache && next build && next export && touch out/.nojekyll && git add out/ && git commit -m \"Deploy Next.js to gh-pages\" && git subtree push --prefix out origin gh-pages" + }, + "dependencies": { + "next": "latest", + "react": "^16.0.0", + "react-dom": "^16.0.0" + }, + "license": "ISC", + "devDependencies": { + "babel-plugin-transform-define": "^1.3.0" + } +} diff --git a/examples/gh-pages/pages/about.js b/examples/gh-pages/pages/about.js new file mode 100644 index 00000000..f5970c48 --- /dev/null +++ b/examples/gh-pages/pages/about.js @@ -0,0 +1,7 @@ +import Link from 'next/link' +export default () => ( +
+
About us
+
Back to Home
+
+) diff --git a/examples/gh-pages/pages/index.js b/examples/gh-pages/pages/index.js new file mode 100644 index 00000000..e79c7bd5 --- /dev/null +++ b/examples/gh-pages/pages/index.js @@ -0,0 +1,4 @@ +import Link from 'next/link' +export default () => ( +
Hello World. About
+)