提交 8b48508c 编写于 作者: R Rafael Almeida 提交者: Luis Alvarez D

Remove inferno example (#9108)

上级 ff5dcacc
# Inferno example
> **Important**: Inferno does not support hooks nor Suspense. It may work on development where React is utilized instead of Inferno, but it will break as soon as you try to build it or start it out of development.
## How to use
### Using `create-next-app`
Execute [`create-next-app`](https://github.com/zeit/next.js/tree/canary/packages/create-next-app) with [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) or [npx](https://github.com/zkat/npx#readme) to bootstrap the example:
```bash
npx create-next-app --example using-inferno using-inferno-app
# or
yarn create next-app --example using-inferno using-inferno-app
```
### Download manually
Download the example:
```bash
curl https://codeload.github.com/zeit/next.js/tar.gz/canary | tar -xz --strip=2 next.js-canary/examples/using-inferno
cd using-inferno
```
Install it and run:
```bash
npm install
npm run dev
# or
yarn
yarn 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 [Inferno](https://github.com/infernojs/inferno), an insanely fast, 9kb React-like library for building high-performance user interfaces on both the client and server. Here we've customized Next.js to use Inferno instead of React in the production build.
Here's how we did it:
- Use `next.config.js` to customize our webpack config to support [inferno-compat](https://www.npmjs.com/package/inferno-compat)
- Create `lib/inferno-compat.js` to polyfill the `React.createContext` API (required by Next.js) that is not available by `inferno-compat`
const React = require('inferno-compat')
const createContext = require('create-react-context/lib/implementation')
Object.keys(React).forEach(key => {
if (key === 'default' || key === '__esModule') return
exports[key] = React[key]
})
// bypass export of React.createContext
exports.createContext = createContext
exports.default = React.default
const path = require('path')
module.exports = {
webpack: function (config, { dev }) {
// For the development version, we'll use React.
// Because, it support react hot loading and so on.
if (dev) {
return config
}
config.resolve.alias = {
...config.resolve.alias,
react: path.resolve('./lib/inferno-compat.js'),
'react-dom': path.resolve('./lib/inferno-compat.js'),
'react-dom/server': 'inferno-server'
}
return config
}
}
{
"name": "using-inferno",
"version": "1.0.0",
"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "NODE_ENV=production node server.js"
},
"dependencies": {
"create-react-context": "0.3.0",
"inferno": "7.3.2",
"inferno-compat": "7.3.2",
"inferno-server": "7.3.2",
"module-alias": "^2.0.0",
"next": "latest",
"react": "^16.7.0",
"react-dom": "^16.7.0"
},
"license": "MIT"
}
import React from 'react'
export default () => <div>About us</div>
import React from 'react'
import Link from 'next/link'
export default () => (
<div>
Hello World.{' '}
<Link href='/about'>
<a>About</a>
</Link>
</div>
)
const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const moduleAlias = require('module-alias')
const path = require('path')
// For the development version, we'll use React.
// Because, it support react hot loading and so on.
if (!dev) {
moduleAlias.addAlias('react', path.resolve('./lib/inferno-compat.js'))
moduleAlias.addAlias('react-dom/server', 'inferno-server')
moduleAlias.addAlias('react-dom', path.resolve('./lib/inferno-compat.js'))
}
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}`)
})
})
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册