|
1 |
| -// const Module = require('module') |
| 1 | +const Module = require('module') |
2 | 2 | const path = require('path')
|
3 | 3 | const withCSS = require('@zeit/next-css')
|
4 | 4 | const withImages = require('next-images')
|
5 | 5 | const resolveFrom = require('resolve-from')
|
6 | 6 |
|
7 | 7 | const node_modules = path.resolve(__dirname, 'node_modules')
|
8 | 8 |
|
9 |
| -// const originalRequire = Module.prototype.require |
| 9 | +const originalRequire = Module.prototype.require |
10 | 10 |
|
11 |
| -// // The following ensures that there is always only a single (and same) |
12 |
| -// // copy of React in an app at any given moment. |
13 |
| -// Module.prototype.require = function(modulePath) { |
14 |
| -// // Only redirect resolutions to non-relative and non-absolute modules |
15 |
| -// if (['/react/', '/react-dom/'].some(d => { |
16 |
| -// try { |
17 |
| -// return require.resolve(modulePath).includes(d) |
18 |
| -// } catch (err) { |
19 |
| -// return false |
20 |
| -// } |
21 |
| -// })) { |
22 |
| -// console.log(modulePath) |
23 |
| -// try { |
24 |
| -// modulePath = resolveFrom( |
25 |
| -// node_modules, |
26 |
| -// modulePath |
27 |
| -// ) |
28 |
| -// console.log('New: ', modulePath) |
29 |
| -// } catch (err) { |
30 |
| -// // |
31 |
| -// } |
32 |
| -// } |
| 11 | +// The following ensures that there is always only a single (and same) |
| 12 | +// copy of React in an app at any given moment. |
| 13 | +Module.prototype.require = function(modulePath) { |
| 14 | + // Only redirect resolutions to non-relative and non-absolute modules |
| 15 | + if (['/react/', '/react-dom/'].some(d => { |
| 16 | + try { |
| 17 | + return require.resolve(modulePath).includes(d) |
| 18 | + } catch (err) { |
| 19 | + return false |
| 20 | + } |
| 21 | + })) { |
| 22 | + console.log(modulePath) |
| 23 | + try { |
| 24 | + modulePath = resolveFrom( |
| 25 | + node_modules, |
| 26 | + modulePath |
| 27 | + ) |
| 28 | + console.log('New: ', modulePath) |
| 29 | + } catch (err) { |
| 30 | + // |
| 31 | + } |
| 32 | + } |
33 | 33 |
|
34 |
| -// return originalRequire.call(this, modulePath) |
35 |
| -// } |
| 34 | + return originalRequire.call(this, modulePath) |
| 35 | +} |
36 | 36 |
|
37 | 37 | const baseConfig = {
|
38 | 38 | // target: 'serverless',
|
|
0 commit comments