Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
4dd4df10
Commit
4dd4df10
authored
Oct 16, 2019
by
Rafael Almeida
Committed by
Joe Haddad
Oct 16, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[using-preact] Update example to Preact X (#9079)
* Update preact example with Preact X * Update README
parent
0886a123
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
9 deletions
+28
-9
README.md
examples/using-preact/README.md
+3
-2
next.config.js
examples/using-preact/next.config.js
+12
-2
package.json
examples/using-preact/package.json
+8
-4
server.js
examples/using-preact/server.js
+5
-1
No files found.
examples/using-preact/README.md
View file @
4dd4df10
#
Hello World
example
#
Preact
example
## How to use
## How to use
...
@@ -43,4 +43,5 @@ This example uses [Preact](https://github.com/developit/preact) instead of React
...
@@ -43,4 +43,5 @@ This example uses [Preact](https://github.com/developit/preact) instead of React
Here's how we did it:
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`
examples/using-preact/next.config.js
View file @
4dd4df10
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
}
}
examples/using-preact/package.json
View file @
4dd4df10
...
@@ -7,10 +7,14 @@
...
@@ -7,10 +7,14 @@
"start"
:
"NODE_ENV=production node server.js"
"start"
:
"NODE_ENV=production node server.js"
},
},
"dependencies"
:
{
"dependencies"
:
{
"
@zeit/next-preact"
:
"0.1.0
"
,
"
module-alias"
:
"2.2.2
"
,
"next"
:
"latest"
,
"next"
:
"latest"
,
"preact"
:
"
8.2.7
"
,
"preact"
:
"
10.0.0
"
,
"preact-
compat"
:
"3.18.0
"
"preact-
render-to-string"
:
"5.0.7
"
},
},
"license"
:
"ISC"
"license"
:
"ISC"
,
"devDependencies"
:
{
"react"
:
"16.10.2"
,
"react-dom"
:
"16.10.2"
}
}
}
examples/using-preact/server.js
View file @
4dd4df10
const
port
=
parseInt
(
process
.
env
.
PORT
,
10
)
||
3000
const
port
=
parseInt
(
process
.
env
.
PORT
,
10
)
||
3000
const
dev
=
process
.
env
.
NODE_ENV
!==
'production'
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
{
createServer
}
=
require
(
'http'
)
const
{
parse
}
=
require
(
'url'
)
const
{
parse
}
=
require
(
'url'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment