CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/next.config.js
Views: 687
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 removeImports = require("next-remove-imports")();
19
20
module.exports = removeImports({
21
basePath,
22
swcMinify: true, // enable faster RUST-based minifier
23
env: { BASE_PATH },
24
reactStrictMode: false, // See https://github.com/ant-design/ant-design/issues/26136
25
eslint: { ignoreDuringBuilds: true },
26
// typescript: { ignoreBuildErrors: true },
27
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
28
config.cache = {
29
type: "filesystem",
30
buildDependencies: {
31
config: [__filename],
32
},
33
cacheDirectory,
34
};
35
// Webpack breaks without this pg-native alias, even though it's dead code,
36
// due to how the pg module does package detection internally.
37
config.resolve.alias["pg-native"] = ".";
38
// These aliases are so we don't end up with two distinct copies
39
// of React in our application, since this doesn't work at all!
40
config.resolve.alias["react"] = resolve(__dirname, "node_modules", "react");
41
config.resolve.alias["react-dom"] = resolve(
42
__dirname,
43
"node_modules",
44
"react-dom",
45
);
46
config.ignoreWarnings = [
47
// This yargs warning is caused by node-zendesk in the @cocalc/server package
48
// being a generally bad citizen. Things seem to work fine (we barely use the
49
// zendesk api anyways).
50
{ module: /^\.\.\/server\/node_modules\/yargs.*/ },
51
];
52
53
// Important: return the modified config
54
return config;
55
},
56
// This is because the debug module color support would otherwise log this warning constantly:
57
// Module not found: ESM packages (supports-color) need to be imported. Use 'import' to
58
// reference the package instead. https://nextjs.org/docs/messages/import-esm-externals
59
experimental: {
60
esmExternals: "loose",
61
// We raise largePageDataBytes since this was recently added, and breaks a lot of SSR rendering
62
// for cocalc share server. By default this is 128 * 1000 = "128KB", and we are changing it to
63
// 128 * 1000 * 15 = "1MB" for now. TODO: Obviously, it would be nice to fix the root causes of this
64
// being too big, but that's for another day, since our production website is broken right now.
65
largePageDataBytes: 128 * 1000 * 10,
66
// If you click the back button in the browser, it should go back to the previous page and restore the scroll position.
67
// With Next.js in the loop, this doesn't happen by default.
68
// besides the ticket about this, here is a blogpost about this
69
// https://www.joshwcomeau.com/react/nextjs-scroll-restoration/
70
scrollRestoration: true,
71
// https://nextjs.org/docs/app/building-your-application/optimizing/memory-usage#webpack-build-worker
72
webpackBuildWorker: true,
73
},
74
// For i18n, see https://nextjs.org/docs/advanced-features/i18n-routing
75
// We are doing this at all since it improves our Lighthouse accessibility score.
76
i18n: {
77
locales: ["en-US"],
78
defaultLocale: "en-US",
79
},
80
poweredByHeader: false, // https://github.com/sagemathinc/cocalc/issues/6101
81
});
82
83