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

[Examples] using-preact: add Prefresh, DevTools & chunking fix #13976

Merged
merged 4 commits into from
Jun 9, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
34 changes: 34 additions & 0 deletions examples/using-preact/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const withPrefresh = require('@prefresh/next')

module.exports = withPrefresh({
webpack(config, { dev, isServer }) {
// Move Preact into the framework chunk instead of duplicating in routes:
const splitChunks = config.optimization && config.optimization.splitChunks
if (splitChunks) {
const cacheGroups = splitChunks.cacheGroups
const test = /[\\/]node_modules[\\/](preact|preact-render-to-string|preact-context-provider)[\\/]/
if (cacheGroups.framework) {
cacheGroups.preact = Object.assign({}, cacheGroups.framework, { test })
cacheGroups.commons.name = 'framework'
} else {
cacheGroups.preact = { name: 'commons', chunks: 'all', test }
}
}

// Install webpack aliases:
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
})
}

return config
},
})
13 changes: 9 additions & 4 deletions examples/using-preact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@
"build": "next build",
"start": "next start"
},
"devDependencies": {
"@prefresh/next": "^0.3.0",
"react-refresh": "^0.8.3"
},
"dependencies": {
"next": "^9.2.3-canary.21",
"preact": "^10.2.1",
"preact-render-to-string": "^5.1.4",
"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-dom": "github:preact-compat/react-dom#1.0.0",
"react-ssr-prepass": "npm:preact-ssr-prepass@^1.0.1"
Copy link
Member

@Timer Timer Jun 9, 2020

Choose a reason for hiding this comment

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

This package no longer lives inside Next.js. We can probably remove it.

And it was only ever used for an experimental feature.

}
}