-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathnext.config.js
132 lines (122 loc) · 3.85 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
const webpack = require("webpack");
const bb = require('browser-builtins');
const nextEnv = require('next-env');
const dotenvLoad = require('dotenv-load');
const { i18n } = require('./next-i18next.config');
dotenvLoad();
const withNextEnv = nextEnv();
// const NEXT_PUBLIC_DEEPLINKS_URL = process.env.NEXT_PUBLIC_DEEPLINKS_URL || 'http://localhost:3006';
const DOCKER = !!+process.env.DOCKER;
const DEEPLINKS_URL = DOCKER ? 'http://host.docker.internal:3006' : 'http://localhost:3006';
/** @type {import('next').NextConfig}*/
const config = {
...((process.env.GITHUB_REPOSITORY && !DOCKER) ? {
basePath: `/${process.env.GITHUB_REPOSITORY.split('/')[1]}`,
} : {}),
distDir: 'app',
strictMode: false,
output: (+process.env.NEXT_PUBLIC_EXPORT) ? 'export' : 'standalone',
webpack5: true,
future: { webpack5: true },
async headers() {
return [
{
source: "/api/:path*",
headers: [
{ key: "Access-Control-Allow-Origin", value: "*" },
]
}
]
},
async rewrites() {
return [
{
source: '/api/:gql*',
destination: `${DEEPLINKS_URL}/:gql*`
// destination: `${NEXT_PUBLIC_DEEPLINKS_URL}/:gql*`
},
{
source: '/api/:file*',
destination: `${DEEPLINKS_URL}/:file*`
// destination: `${NEXT_PUBLIC_DEEPLINKS_URL}/:file*`
},
]
},
webpack: (config, { isServer }) => {
// Exclude .tsx and .ts files
const excludePattern = /\.(ts|tsx)?$/;
config.module.rules.push({
test: excludePattern,
exclude: /node_modules/,
use: [],
});
config.resolve.extensions = config.resolve.extensions.filter(item => !excludePattern.test(item));
config.module.rules.push({
test: /\.cozo$/,
use: 'raw-loader',
});
// config.resolve.alias = {
// ...(config.resolve.alias || {}),
// "node:buffer": require.resolve('buffer/'),
// };
// if (!isServer) {
config.resolve.fallback = {
// "buffer": require.resolve('buffer/'),
"child_process": false,
"dgram": false,
"net": false,
"dns": false,
"module": false,
"os": false,
"fs": false,
"tls": false,
"net": false,
"path": false,
"zlib": false,
"http": false,
"https": false,
"stream": false,
"crypto": false,
};
// }
// config.resolve.fallback = {
// "buffer": require.resolve('buffer/'),
// "fs": require.resolve("browserify-fs"),
// "util": require.resolve("util"),
// "http": require.resolve("stream-http"),
// "https": require.resolve("https-browserify"),
// "tls": require.resolve("tls-browserify"),
// "net": require.resolve("net-browserify"),
// "crypto": require.resolve("crypto-browserify"),
// "path": require.resolve("path-browserify"),
// "os": require.resolve("os-browserify"),
// "stream": require.resolve("stream-browserify"),
// "zlib": require.resolve("browserify-zlib")
// };
// console.log(config.plugins);
config.plugins.push(
new webpack.ProvidePlugin({
process: "process/browser",
Buffer: ["buffer", "Buffer"],
}),
new webpack.NormalModuleReplacementPlugin(/node:/, (resource) => {
const mod = resource.request.replace(/^node:/, "");
switch (mod) {
case "buffer":
resource.request = "buffer";
break;
case "stream":
resource.request = "readable-stream";
break;
default:
if (bb[mod]) resource.request = bb[mod];
else throw new Error(`Not found ${mod}`);
}
}),
// new WorkerUrlPlugin(),
);
return config;
},
...(+(process?.env?.NEXT_PUBLIC_I18N_DISABLE || 0) ? {} : { i18n }),
};
module.exports = withNextEnv(config);