-
Notifications
You must be signed in to change notification settings - Fork 1
/
next.config.js
31 lines (26 loc) · 816 Bytes
/
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
const fs = require('fs')
let isUpdating = false
const postLib = `${__dirname}/src/pages/posts/[id].tsx`
const onChangePost = () => {
if (isUpdating) return
isUpdating = true
const content = fs.readFileSync(postLib, 'utf-8')
// libファイルにコードを書き加えて強制的にHMRを起こす
fs.writeFileSync(
postLib,
`${content}\nconsole.log('updatedAt: ${new Date().toISOString()}')`
)
// 1秒後に元に戻す
setTimeout(() => {
fs.writeFileSync(postLib, content)
isUpdating = false
}, 1000)
}
require('chokidar')
.watch('./posts', { ignoreInitial: true })
.on('add', onChangePost)
.on('change', onChangePost)
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
})
module.exports = withBundleAnalyzer({})