Skip to content

Commit 18ce35d

Browse files
committed
feat: set up "preact" config
1 parent 0f79457 commit 18ce35d

File tree

4 files changed

+627
-46
lines changed

4 files changed

+627
-46
lines changed

.babelrc

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
11
{
2-
"presets": [
3-
[
4-
"next/babel",
5-
{
6-
"preset-react": {
7-
"runtime": "automatic",
8-
"importSource": "@emotion/react"
9-
}
10-
}
11-
]
12-
],
13-
"plugins": ["@emotion/babel-plugin"]
2+
"plugins": [],
3+
"presets": ["next/babel", "@emotion/babel-preset-css-prop"]
144
}

next.config.js

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
const computePath = require('./utils').computePath
2+
const withPrefresh = require('@prefresh/next')
23

3-
module.exports = {
4-
webpack(config, options) {
4+
const config = {
5+
experimental: {
6+
modern: true,
7+
polyfillsOptimization: true,
8+
},
9+
10+
webpack(config, { dev, isServer }) {
511
const esLintRule = {
612
test: /\.tsx$/,
713
enforce: 'pre',
814
exclude: ['/node_modules/', '/.next/'],
9-
loader: 'eslint-loader'
15+
loader: 'eslint-loader',
1016
}
1117
config.module.rules.push(esLintRule)
1218

@@ -24,6 +30,41 @@ module.exports = {
2430
utils: computePath('./src/utils')
2531
}
2632

33+
// Preact stuff
34+
const splitChunks = config.optimization && config.optimization.splitChunks
35+
if (splitChunks) {
36+
const cacheGroups = splitChunks.cacheGroups
37+
const preactModules = /[\\/]node_modules[\\/](preact|preact-render-to-string|preact-context-provider)[\\/]/
38+
if (cacheGroups.framework) {
39+
cacheGroups.preact = Object.assign({}, cacheGroups.framework, {
40+
test: preactModules,
41+
})
42+
cacheGroups.commons.name = 'framework'
43+
} else {
44+
cacheGroups.preact = {
45+
name: 'commons',
46+
chunks: 'all',
47+
test: preactModules,
48+
}
49+
}
50+
}
51+
52+
// Install webpack aliases:
53+
const aliases = config.resolve.alias || (config.resolve.alias = {})
54+
aliases.react = aliases['react-dom'] = 'preact/compat'
55+
56+
// inject Preact DevTools
57+
if (dev && !isServer) {
58+
const entry = config.entry
59+
config.entry = () =>
60+
entry().then(entries => {
61+
entries['main.js'] = ['preact/debug'].concat(entries['main.js'] || [])
62+
return entries
63+
})
64+
}
65+
2766
return config
28-
}
67+
},
2968
}
69+
70+
module.exports = withPrefresh(config)

0 commit comments

Comments
 (0)