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

Implement preact/inferno SSR #1346

Merged
merged 3 commits into from
Mar 5, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 7 additions & 1 deletion examples/using-inferno/next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
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': 'inferno-compat',
'react-dom': 'inferno-compat'
Expand Down
6 changes: 4 additions & 2 deletions examples/using-inferno/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
"name": "using-inferno",
"version": "1.0.0",
"scripts": {
"dev": "next",
"dev": "node server.js",
"build": "next build",
"start": "next start"
"start": "NODE_ENV=production node server.js"
},
"dependencies": {
"inferno": "^1.0.7",
"inferno-compat": "^1.0.7",
"inferno-server": "^1.3.0-rc.9",
"module-alias": "^2.0.0",
"next": "^2.0.0-beta",
"react": "^15.4.2",
"react-dom": "^15.4.2"
Expand Down
29 changes: 29 additions & 0 deletions examples/using-inferno/server.js
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')
})
})
19 changes: 18 additions & 1 deletion examples/using-preact/next.config.js
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
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about simplifying this to:

config.plugins = config.plugins.filter((plugin) => (plugin.constructor.name !== 'UglifyJsPlugin'))

or at least drop the redundant if/return true/false:

config.plugins = config.plugins.filter((plugin) => {
    return plugin.constructor.name !== 'UglifyJsPlugin'
})

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I copied this one: #1195 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... "Good catch. I don't care." Was it the case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, didn't get to changing it before rauchg merged it 😅 Will send a PR 👍🏻👍🏻

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

})

return config
}
}
5 changes: 3 additions & 2 deletions examples/using-preact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
"name": "hello-world",
"version": "1.0.0",
"scripts": {
"dev": "next",
"dev": "node server.js",
"build": "next build",
"start": "next start"
"start": "NODE_ENV=production node server.js"
},
"dependencies": {
"module-alias": "^2.0.0",
"next": "^2.0.0-beta",
"preact": "^7.1.0",
"preact-compat": "^3.9.4",
Expand Down
28 changes: 28 additions & 0 deletions examples/using-preact/server.js
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')
})
})