forked from 1instinct/dna-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
next.config.js
72 lines (69 loc) · 1.93 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
const Module = require("module");
const path = require("path");
const resolveFrom = require("resolve-from");
const Dotenv = require("dotenv-webpack");
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);
};
const DEPLOY_ENV =
process.env.DEPLOY_ENV && process.env.DEPLOY_ENV.toLowerCase();
const DEPLOY_ENV_MAPPING = {
dev: "development",
staging: "staging",
prod: "production"
};
const envFile = path.join(__dirname, `.env.${DEPLOY_ENV_MAPPING[DEPLOY_ENV]}`);
loadEnvVariables();
const isLocalDevEnvironment = !process.env.DEPLOY_ENV;
module.exports = {
swcMinify: true,
webpack: (config, { webpack }) => {
config.plugins = config.plugins || [];
config.plugins = [
...config.plugins,
new Dotenv({
path: envFile,
systemvars: true
})
];
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;
}
};
function loadEnvVariables() {
// eslint-disable-next-line global-require
require("dotenv").config({
path: envFile
});
}