-
Notifications
You must be signed in to change notification settings - Fork 27.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement preact/inferno SSR (#1346)
* Use module-alias to alias preact server side * Use module-alias to alias inferno server side * Remove unneeded routes example
- Loading branch information
1 parent
bcd582a
commit 5947716
Showing
6 changed files
with
89 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const dev = process.env.NODE_ENV !== 'production' | ||
const moduleAlias = require('module-alias') | ||
|
||
// For the development version, we'll use React. | ||
// Because, it support react hot loading and so on. | ||
if (!dev) { | ||
moduleAlias.addAlias('react', 'inferno-compat') | ||
moduleAlias.addAlias('react-dom/server', 'inferno-server') | ||
moduleAlias.addAlias('react-dom', 'inferno-compat') | ||
} | ||
|
||
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(3000, (err) => { | ||
if (err) throw err | ||
console.log('> Ready on http://localhost:3000') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,26 @@ | ||
module.exports = { | ||
webpack: function (config) { | ||
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 = { | ||
'react': 'preact-compat/dist/preact-compat', | ||
'react-dom': 'preact-compat/dist/preact-compat' | ||
} | ||
|
||
// Disable uglify. This has been fixed in https://github.com/developit/preact-compat/issues/155. | ||
// Can be removed once there is a new preact-compat release. | ||
config.plugins = config.plugins.filter((plugin) => { | ||
if (plugin.constructor.name === 'UglifyJsPlugin') { | ||
return false | ||
} else { | ||
return true | ||
} | ||
}) | ||
|
||
return config | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const dev = process.env.NODE_ENV !== 'production' | ||
const moduleAlias = require('module-alias') | ||
|
||
// For the development version, we'll use React. | ||
// Because, it support react hot loading and so on. | ||
if (dev) { | ||
moduleAlias.addAlias('react', 'preact-compat') | ||
moduleAlias.addAlias('react-dom', 'preact-compat') | ||
} | ||
|
||
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(3000, (err) => { | ||
if (err) throw err | ||
console.log('> Ready on http://localhost:3000') | ||
}) | ||
}) |