-
Notifications
You must be signed in to change notification settings - Fork 0
/
next.config.js
48 lines (43 loc) · 1.22 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
const Module = require('module')
const path = require('path')
const resolveFrom = require('resolve-from')
const node_modules = path.resolve(__dirname, 'node_modules')
const originalRequire = Module.prototype.require
// The following ensures that there is always only a single (and same)
// copy of React in an app at any given moment.
Module.prototype.require = function (modulePath) {
// Only redirect resolutions to non-relative and non-absolute modules
if (
['/react/', '/react-dom/', '/react-query/'].some(d => {
try {
return require.resolve(modulePath).includes(d)
} catch (err) {
return false
}
})
) {
try {
modulePath = resolveFrom(node_modules, modulePath)
} catch (err) {
//
}
}
return originalRequire.call(this, modulePath)
}
module.exports = {
webpack: config => {
config.resolve = {
...config.resolve,
alias: {
...config.resolve.alias,
react$: resolveFrom(path.resolve('node_modules'), 'react'),
'react-query$': resolveFrom(
path.resolve('node_modules'),
'react-query'
),
'react-dom$': resolveFrom(path.resolve('node_modules'), 'react-dom'),
},
}
return config
},
}