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