Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[using-preact] Update example to Preact X #9079

Merged
merged 3 commits into from
Oct 16, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions examples/using-preact/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Hello World example
# Preact example

## How to use

Expand Down Expand Up @@ -43,4 +43,5 @@ This example uses [Preact](https://github.com/developit/preact) instead of React

Here's how we did it:

- Use `next.config.js` to customize our webpack config to support [preact-compat](https://github.com/developit/preact-compat)
- Use `next.config.js` to customize our webpack config by aliasing React to `preact/compat`
- Use `server.js` to make our server use Preact by aliasing React to `preact/compat`
14 changes: 12 additions & 2 deletions examples/using-preact/next.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
const withPreact = require('@zeit/next-preact')
module.exports = {
webpack: function (config) {
config.resolve.alias = {
...config.resolve.alias,
react: 'preact/compat',
react$: 'preact/compat',
'react-dom': 'preact/compat',
'react-dom$': 'preact/compat'
}

module.exports = withPreact()
return config
}
}
12 changes: 8 additions & 4 deletions examples/using-preact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
"start": "NODE_ENV=production node server.js"
},
"dependencies": {
"@zeit/next-preact": "0.1.0",
"module-alias": "2.2.2",
"next": "latest",
"preact": "8.2.7",
"preact-compat": "3.18.0"
"preact": "10.0.0",
"preact-render-to-string": "5.0.7"
},
"license": "ISC"
"license": "ISC",
"devDependencies": {
"react": "16.10.2",
"react-dom": "16.10.2"
}
}
6 changes: 5 additions & 1 deletion examples/using-preact/server.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const moduleAlias = require('module-alias')

require('@zeit/next-preact/alias')()
moduleAlias.addAliases({
react: 'preact/compat',
'react-dom': 'preact/compat'
})

const { createServer } = require('http')
const { parse } = require('url')
Expand Down