-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathnext.config.ts
159 lines (150 loc) · 7.01 KB
/
next.config.ts
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import type { Compilation, Compiler, Configuration } from "webpack";
import { access, symlink } from "fs/promises";
import CopyPlugin from "copy-webpack-plugin";
import type { NextConfig } from "next";
import { join } from "path";
import { platform } from "os";
if (process.env.BASE_PATH && !process.env.BASE_PATH.startsWith("/")) {
const errorMessage = "process.env.BASE_PATH must start with a '/' found " + process.env.BASE_PATH;
// eslint-disable-next-line no-console
console.error(errorMessage);
throw new Error(errorMessage);
}
/** @type {import('next').NextConfig} */
const nextConfig: NextConfig = {
eslint: {
// Warning: This allows production builds to successfully complete even if
// your project has ESLint errors.
ignoreDuringBuilds: true
},
// swcMinify: true,
// Base path doesn't work because it changes the path on the local server. We actually are running via a proxy base path
// https://nextjs.org/docs/api-reference/next.config.js/basepath
// https://stackoverflow.com/questions/60452054/nextjs-deploy-to-a-specific-url-path
// https://levelup.gitconnected.com/deploy-your-nextjs-application-on-a-different-base-path-i-e-not-root-1c4d210cce8a?gi=fb4f2031b0d1
// basePath: process.env.BASE_PATH || undefined,
// https://nextjs.org/docs/api-reference/next.config.js/cdn-support-with-asset-prefix
assetPrefix: process.env.ASSET_PREFIX || (process.env.BASE_PATH ? process.env.BASE_PATH + "/" : undefined),
compiler: {
styledComponents: {
displayName: true,
ssr: true
// ["styled-components", { "ssr": true, "displayName": true, "preprocess": false } ]
}
},
experimental: {
typedRoutes: true
// instrumentationHook: true,
},
// Defaults to any but is actually type { import('webpack').Configuration }
webpack: (config: Configuration, { isServer, dir: optionsDir }) => {
const wasmExtensionRegExp = /\.wasm$/;
if (!config.resolve) { config.resolve = {}; }
if (!config.resolve.extensions) { config.resolve.extensions = []; }
config.resolve.extensions.push(".wasm");
config.module?.rules?.forEach((rule: any) => {
(rule.oneOf || []).forEach((oneOf: any) => {
if (oneOf.loader && oneOf.loader.indexOf("file-loader") >= 0) {
// Make file-loader ignore WASM files
oneOf.exclude.push(wasmExtensionRegExp);
}
});
});
if (!config.output) { config.output = {}; }
config.output.webassemblyModuleFilename = "static/wasm/[modulehash].wasm";
if (!config.experiments) { config.experiments = {}; }
config.experiments.asyncWebAssembly = true;
// https://github.com/vercel/next.js/issues/25852
// Compiling we run into an issue where it can't find the config wasm.
// On Linux the workaround is to create a symlink to the correct location
// On Windows, the symlinks fail so we must copy the file
if (!config.plugins) { config.plugins = []; }
config.plugins.push(
platform() === "win32"
// https://github.com/vercel/next.js/issues/25852#issuecomment-1727385542
? new CopyPlugin({
patterns: [
{ from: "../lib/config-wasm/pkg/config_wasm_bg.wasm", to: "./" }
]
})
// https://github.com/vercel/next.js/issues/25852#issuecomment-1057059000
: new (class {
apply (compiler: Compiler) {
compiler.hooks.afterEmit.tapPromise(
"SymlinkWebpackPlugin",
async (compilation: Compilation) => {
if (isServer) {
const from = join(compilation.options.output.path!, "config_wasm_bg.wasm");
const to = join(optionsDir, "../lib/config-wasm/pkg/config_wasm_bg.wasm");
// options.dir /.../pewpew/controller
// console.log(`from/to: ${from} -> ${to}`);
try {
await access(from);
// eslint-disable-next-line no-console
console.log(`${from} already exists`);
return;
} catch (error: any) {
if (error?.code === "ENOENT") {
// No link exists
} else {
// eslint-disable-next-line no-console
console.error(`access ${from} error ${error}`, error);
throw error;
}
}
await symlink(to, from, "junction");
// eslint-disable-next-line no-console
console.log(`created symlink ${from} -> ${to}`);
}
}
);
}
})()
);
return config;
},
distDir: "dist",
// env: {} // env variables are set at build time, not run time. They are better optimized during the build process
publicRuntimeConfig: { // These are sent to the client and the server and are set at run time
LOGGING_LEVEL: process.env.LOGGING_LEVEL || process.env.LoggingLevel,
APPLICATION_NAME: process.env.APPLICATION_NAME,
SYSTEM_NAME: process.env.SYSTEM_NAME,
FS_SITE: process.env.FS_SITE,
NODE_ENV: process.env.NODE_ENV,
BASE_PATH: process.env.BASE_PATH,
ASSET_PREFIX: process.env.ASSET_PREFIX,
TEST_STATUS_REFRESH_DELAY: process.env.TEST_STATUS_REFRESH_DELAY,
TEST_ERRORS_MAX_DISPLAYED: process.env.TEST_ERRORS_MAX_DISPLAYED,
TEST_ERRORS_MAX_LINE_LENGTH: process.env.TEST_ERRORS_MAX_LINE_LENGTH,
TEST_AUTH_PERMISSION: process.env.TEST_AUTH_PERMISSION,
REDIRECT_TO_S3: process.env.REDIRECT_TO_S3,
UNZIP_S3_FILES: process.env.UNZIP_S3_FILES,
AUTH_MODE: process.env.AUTH_MODE,
OPENID_ONLY_ADMIN_RUN_TESTS: process.env.OPENID_ONLY_ADMIN_RUN_TESTS,
TEST_LOCALHOST: process.env.TEST_LOCALHOST,
CNAME_DOMAIN: process.env.CNAME_DOMAIN,
ROUTING_DOMAIN: process.env.ROUTING_DOMAIN,
AUTH_COOKIE_PATH: process.env.AUTH_COOKIE_PATH,
AUTH_COOKIE_NAME: process.env.AUTH_COOKIE_NAME,
REFRESH_COOKIE_NAME: process.env.REFRESH_COOKIE_NAME,
HINT_COOKIE_NAME: process.env.HINT_COOKIE_NAME,
AUTH_HEADER_NAME: process.env.AUTH_HEADER_NAME,
COOKIE_DURATION_DAYS: process.env.COOKIE_DURATION_DAYS,
REFRESH_COOKIE_DURATION_DAYS: process.env.REFRESH_COOKIE_DURATION_DAYS,
HIDE_ENVIRONMENT: process.env.HIDE_ENVIRONMENT
},
// https://github.com/vercel/next.js/discussions/11493#discussioncomment-14606
env: { // These are sent to the client and the server and are set at build time for static pages
LOGGING_LEVEL: process.env.LOGGING_LEVEL || process.env.LoggingLevel || "", // Only checks if debug
APPLICATION_NAME: process.env.APPLICATION_NAME,
SYSTEM_NAME: process.env.SYSTEM_NAME,
FS_SITE: process.env.FS_SITE, // Used by auth client/Layout
BASE_PATH: process.env.BASE_PATH, // client utils/Layout
ASSET_PREFIX: process.env.ASSET_PREFIX, // client utils/Layout
HIDE_ENVIRONMENT: process.env.HIDE_ENVIRONMENT, // Used by Layout
AUTH_MODE: process.env.AUTH_MODE, // Used by auth client/Layout
AUTH_COOKIE_NAME: process.env.AUTH_COOKIE_NAME, // Used by auth client/Layout
AUTH_HEADER_NAME: process.env.AUTH_HEADER_NAME // Used by auth client/Layout
}
};
module.exports = nextConfig;