Unverified Commit 629884af authored by Yuji Matsumoto's avatar Yuji Matsumoto Committed by GitHub

Update using-preact example's dependencies (#18493)

- Update Next.js version to 10.0.0
- Update the other dependencies
- Modify `next.config.js` to prevent circular `__self` and `__source`in dev env (ref: https://github.com/developit/nextjs-preact-demo/issues/25)
parent 598df6ac
const preact = require('preact')
const withPrefresh = require('@prefresh/next')
module.exports = withPrefresh({
......@@ -25,14 +26,32 @@ module.exports = withPrefresh({
const aliases = config.resolve.alias || (config.resolve.alias = {})
aliases.react = aliases['react-dom'] = 'preact/compat'
// Automatically inject Preact DevTools:
if (dev && !isServer) {
const entry = config.entry
config.entry = () =>
entry().then((entries) => {
entries['main.js'] = ['preact/debug'].concat(entries['main.js'] || [])
return entries
})
if (dev) {
if (isServer) {
// Remove circular `__self` and `__source` props only meant for development
let oldVNodeHook = preact.options.vnode
preact.options.vnode = (vnode) => {
const props = vnode.props
if (props != null) {
if ('__self' in props) props.__self = null
if ('__source' in props) props.__source = null
}
if (oldVNodeHook) {
oldVNodeHook(vnode)
}
}
} else {
// Automatically inject Preact DevTools:
const entry = config.entry
config.entry = () =>
entry().then((entries) => {
entries['main.js'] = ['preact/debug'].concat(
entries['main.js'] || []
)
return entries
})
}
}
return config
......
......@@ -6,17 +6,15 @@
"build": "next build",
"start": "next start"
},
"devDependencies": {
"react-refresh": "^0.8.3"
},
"devDependencies": {},
"dependencies": {
"@prefresh/next": "^0.3.0",
"next": "^9.4.0",
"preact": "^10.4.4",
"preact-render-to-string": "^5.1.9",
"react": "github:preact-compat/react#1.0.0",
"react-dom": "github:preact-compat/react-dom#1.0.0",
"react-ssr-prepass": "npm:preact-ssr-prepass@^1.0.1"
"@prefresh/next": "^1.3.0",
"next": "10.0.0",
"preact": "^10.5.4",
"preact-render-to-string": "^5.1.10",
"react": "npm:@preact/compat@^0.0.3",
"react-dom": "npm:@preact/compat@^0.0.3",
"react-ssr-prepass": "npm:preact-ssr-prepass@^1.1.2"
},
"license": "MIT"
}
......@@ -4,9 +4,23 @@ export default function Home() {
return (
<div>
Hello World.{' '}
<Link href="/about">
<a>About</a>
</Link>
<ul>
<li>
<Link href="/about">
<a>About</a>
</Link>
</li>
<li>
<Link href="/ssr">
<a>SSR</a>
</Link>
</li>
<li>
<Link href="/ssg">
<a>SSG</a>
</Link>
</li>
</ul>
</div>
)
}
export default function SSG({ framework }) {
return <div>{framework} ssg example</div>
}
export function getStaticProps() {
return {
props: { framework: 'preact' },
}
}
export default function SSR({ framework }) {
return <div>{framework} ssr example</div>
}
export function getServerSideProps() {
return {
props: { framework: 'preact' },
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment