Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/next.config.js
1447 views
1
// next.js defines / to be an invalid basepath, whereas in cocalc it is valid:
2
const BASE_PATH = process.env.BASE_PATH ?? "/";
3
4
// next.js definition:
5
const basePath = BASE_PATH == "/" ? "" : BASE_PATH;
6
7
const { join, resolve } = require("path");
8
9
// Important! We include resolve('.') and basePath to avoid
10
// any possibility of multiple cocalc installs or different base
11
// paths conflicting with each other and causing corruption.
12
const cacheDirectory = join(
13
`/tmp/nextjs-${require("os").userInfo().username}`,
14
basePath,
15
resolve("."),
16
);
17
18
const config = {
19
basePath,
20
env: { BASE_PATH },
21
eslint: { ignoreDuringBuilds: true },
22
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
23
// Webpack breaks without this pg-native alias, even though it's dead code,
24
// due to how the pg module does package detection internally.
25
config.resolve.alias["pg-native"] = ".";
26
// These aliases are so we don't end up with two distinct copies
27
// of React in our application, since this doesn't work at all!
28
config.resolve.alias["react"] = resolve(__dirname, "node_modules", "react");
29
config.resolve.alias["react-dom"] = resolve(
30
__dirname,
31
"node_modules",
32
"react-dom",
33
);
34
// Important: return the modified config
35
return config;
36
},
37
// For i18n, see https://nextjs.org/docs/advanced-features/i18n-routing
38
// We are doing this at all since it improves our Lighthouse accessibility score.
39
i18n: {
40
locales: ["en-US"],
41
defaultLocale: "en-US",
42
},
43
poweredByHeader: false,
44
};
45
46
const withRspack = require("next-rspack");
47
// use NO_RSPACK to build without RSPACK. This is useful on a machine with a lot
48
// of RAM (and patience) since it supports hot module reloading (so you don't have
49
// to refresh after making changes).
50
51
if (process.env.NO_RSPACK) {
52
module.exports = config;
53
} else {
54
module.exports = withRspack(config);
55
}
56
57