// next.js defines / to be an invalid basepath, whereas in cocalc it is valid:1const BASE_PATH = process.env.BASE_PATH ?? "/";23// next.js definition:4const basePath = BASE_PATH == "/" ? "" : BASE_PATH;56const { join, resolve } = require("path");78// Important! We include resolve('.') and basePath to avoid9// any possibility of multiple cocalc installs or different base10// paths conflicting with each other and causing corruption.11const cacheDirectory = join(12`/tmp/nextjs-${require("os").userInfo().username}`,13basePath,14resolve("."),15);1617const config = {18basePath,19env: { BASE_PATH },20eslint: { ignoreDuringBuilds: true },21webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {22// Webpack breaks without this pg-native alias, even though it's dead code,23// due to how the pg module does package detection internally.24config.resolve.alias["pg-native"] = ".";25// These aliases are so we don't end up with two distinct copies26// of React in our application, since this doesn't work at all!27config.resolve.alias["react"] = resolve(__dirname, "node_modules", "react");28config.resolve.alias["react-dom"] = resolve(29__dirname,30"node_modules",31"react-dom",32);33config.devServer = {34hot: true,35};36// Important: return the modified config37return config;38},39// For i18n, see https://nextjs.org/docs/advanced-features/i18n-routing40// We are doing this at all since it improves our Lighthouse accessibility score.41i18n: {42locales: ["en-US"],43defaultLocale: "en-US",44},45poweredByHeader: false,46};4748const withRspack = require("next-rspack");49// use NO_RSPACK to build without RSPACK. This is useful on a machine with a lot50// of RAM (and patience) since it supports hot module reloading (so you don't have51// to refresh after making changes).5253if (process.env.NO_RSPACK) {54module.exports = config;55} else {56module.exports = withRspack(config);57}585960