diff --git a/examples/using-nerv/README.md b/examples/using-nerv/README.md new file mode 100644 index 00000000..0156310f --- /dev/null +++ b/examples/using-nerv/README.md @@ -0,0 +1,44 @@ +[![Deploy to now](https://deploy.now.sh/static/button.svg)](https://deploy.now.sh/?repo=https://github.com/zeit/next.js/tree/master/examples/using-nerv) + +# Hello World example + +## How to use + +### Using `create-next-app` + +Download [`create-next-app`](https://github.com/segmentio/create-next-app) to bootstrap the example: + +``` +npm i -g create-next-app +create-next-app --example using-nerv using-nerv-app +``` + +### 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/canary | tar -xz --strip=2 next.js-canary/examples/using-nerv +cd using-nerv +``` + +Install it and run: + +```bash +npm install +npm run dev +``` + +Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download)) + +```bash +now +``` + +## The idea behind the example + +This example uses [Nerv](https://nerv.aotu.io/) instead of React. It's a "blazing fast React alternative, compatible with IE8 and React 16". Here we've customized Next.js to use Nerv instead of React. + +Here's how we did it: + +* Use `next.config.js` to customize our webpack config to support [Nerv](https://nerv.aotu.io/) diff --git a/examples/using-nerv/next.config.js b/examples/using-nerv/next.config.js new file mode 100644 index 00000000..c709c983 --- /dev/null +++ b/examples/using-nerv/next.config.js @@ -0,0 +1,16 @@ +module.exports = { + webpack: function (config, { dev }) { + // For the development version, we'll use React. + // Because, it supports react hot loading and so on. + if (dev) { + return config + } + + config.resolve.alias = { + react: 'nervjs', + 'react-dom': 'nervjs' + } + + return config + } +} diff --git a/examples/using-nerv/package.json b/examples/using-nerv/package.json new file mode 100644 index 00000000..15cded8d --- /dev/null +++ b/examples/using-nerv/package.json @@ -0,0 +1,21 @@ +{ + "name": "using-nerv", + "version": "1.0.0", + "scripts": { + "dev": "node server.js", + "build": "next build", + "start": "NODE_ENV=production node server.js" + }, + "dependencies": { + "module-alias": "^2.0.0", + "next": "latest", + "nervjs": "^1.2.4", + "react": "^16.0.0", + "react-dom": "^16.0.0" + }, + "license": "ISC", + "devDependencies": { + "react": "~15.6.1", + "react-dom": "~15.6.1" + } +} diff --git a/examples/using-nerv/pages/about.js b/examples/using-nerv/pages/about.js new file mode 100644 index 00000000..6c501fbd --- /dev/null +++ b/examples/using-nerv/pages/about.js @@ -0,0 +1,5 @@ +import React from 'react' + +export default () => ( +
About us
+) diff --git a/examples/using-nerv/pages/index.js b/examples/using-nerv/pages/index.js new file mode 100644 index 00000000..3e6362aa --- /dev/null +++ b/examples/using-nerv/pages/index.js @@ -0,0 +1,6 @@ +import React from 'react' +import Link from 'next/link' + +export default () => ( +
Hello World. About
+) diff --git a/examples/using-nerv/server.js b/examples/using-nerv/server.js new file mode 100644 index 00000000..e28d7afd --- /dev/null +++ b/examples/using-nerv/server.js @@ -0,0 +1,29 @@ +const port = parseInt(process.env.PORT, 10) || 3000 +const dev = process.env.NODE_ENV !== 'production' +const moduleAlias = require('module-alias') + +// For the development version, we'll use React. +// Because, it support react hot loading and so on. +if (!dev) { + moduleAlias.addAlias('react', 'nervjs') + moduleAlias.addAlias('react-dom', 'nervjs') +} + +const { createServer } = require('http') +const { parse } = require('url') +const next = require('next') + +const app = next({ dev }) +const handle = app.getRequestHandler() + +app.prepare() +.then(() => { + createServer((req, res) => { + const parsedUrl = parse(req.url, true) + handle(req, res, parsedUrl) + }) + .listen(port, (err) => { + if (err) throw err + console.log(`> Ready on http://localhost:${port}`) + }) +})