From 1479f46e4fe8f6b2a57eb9f2007df7389de136fb Mon Sep 17 00:00:00 2001 From: Rafael Almeida Date: Tue, 15 Oct 2019 03:05:32 -0300 Subject: [PATCH 1/2] Update preact example with Preact X --- examples/using-preact/next.config.js | 14 ++++++++++++-- examples/using-preact/package.json | 12 ++++++++---- examples/using-preact/server.js | 6 +++++- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/examples/using-preact/next.config.js b/examples/using-preact/next.config.js index 2299135708cd9..8f9129a8294b5 100644 --- a/examples/using-preact/next.config.js +++ b/examples/using-preact/next.config.js @@ -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 + } +} diff --git a/examples/using-preact/package.json b/examples/using-preact/package.json index b2b606c973e73..c9f1e1c54cb2d 100644 --- a/examples/using-preact/package.json +++ b/examples/using-preact/package.json @@ -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" + } } diff --git a/examples/using-preact/server.js b/examples/using-preact/server.js index 638a516a4da29..cfb3cc5c04b0a 100644 --- a/examples/using-preact/server.js +++ b/examples/using-preact/server.js @@ -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') From fdca53f9cf5ba3c7fd0b825161ed26b944673fa7 Mon Sep 17 00:00:00 2001 From: Rafael Almeida Date: Tue, 15 Oct 2019 03:42:11 -0300 Subject: [PATCH 2/2] Update README --- examples/using-preact/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/using-preact/README.md b/examples/using-preact/README.md index 4b9ec50ac02aa..70e4d575474dc 100644 --- a/examples/using-preact/README.md +++ b/examples/using-preact/README.md @@ -1,4 +1,4 @@ -# Hello World example +# Preact example ## How to use @@ -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`