-
Notifications
You must be signed in to change notification settings - Fork 2
/
next.config.js
51 lines (44 loc) · 1.17 KB
/
next.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const path = require("path")
const fs = require("fs")
const cwd = process.cwd()
module.exports = {
future: {
webpack5: true,
},
webpack: (config, { isServer }) => {
if (!isServer) {
config.resolve.fallback.fs = false
}
if (isServer) {
return {
...config,
entry() {
return config.entry().then(async (entry) => {
const targets = ["src/server"]
let workerEntries = {}
for (const target of targets) {
const targetDir = path.resolve(cwd, target)
const workers = await fs.promises.readdir(targetDir)
workerEntries = {
...workerEntries,
...Object.fromEntries(
workers
.filter((filename) => filename.includes(".ts"))
.map((filename) => [
filename.split(".").shift(),
path.resolve(targetDir, filename),
])
),
}
}
return {
...entry,
...workerEntries,
}
})
},
}
}
return config
},
}