forked from Alex-DG/twisted-colorful-sphere
-
Notifications
You must be signed in to change notification settings - Fork 0
/
next.config.js
92 lines (86 loc) Β· 2.19 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const plugins = require('next-compose-plugins')
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
})
// custom transpile module
const debug = false
let start = null
let i = 0
const match = (path) => {
if (!path.includes('three/examples/jsm')) return false
if (debug) {
// should be around 3/4 seconds the first time and then 200ms after using Webpack 5 built-in loader cache
let end = start ? new Date() - start : 0
console.log(
`\x1b[37m`,
`π ${end}ms - The transpilation ${path} in process`
)
if (i === 1) {
start = new Date()
}
i++
}
return true
}
const withOffline = require('next-offline')
const withTM = require('next-transpile-modules')(
['three', '@react-three/drei'], // '@react-three/postprocessing'
{ debug: debug, unstable_webpack5: false, match } // symlink-caused loops which cause memory to get bloated exponentially.
)
const nextConfig = {
webpack(config) {
config.module.rules.push(
{ test: /react-spring/, sideEffects: true }, // prevent vercel to crash when deploy
{
test: /\.(glsl|vs|fs|vert|frag)$/,
exclude: /node_modules/,
use: ['raw-loader', 'glslify-loader'],
}
)
return config
},
}
// manage i18n
if (process.env.EXPORT !== 'true') {
nextConfig.i18n = {
locales: ['en-US'],
defaultLocale: 'en-US',
}
}
module.exports = plugins(
[
withTM(nextConfig),
[
withOffline,
{
workboxOpts: {
swDest: process.env.NEXT_EXPORT
? 'service-worker.js'
: 'static/service-worker.js',
runtimeCaching: [
{
urlPattern: /^https?.*/,
handler: 'NetworkFirst',
options: {
cacheName: 'offlineCache',
expiration: {
maxEntries: 200,
},
},
},
],
},
async rewrites() {
return [
{
source: '/service-worker.js',
destination: '/_next/static/service-worker.js',
},
]
},
},
],
withBundleAnalyzer,
],
nextConfig
)