/** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ // @ts-check const path = require('path'); const npm2yarn = require('@docusaurus/remark-plugin-npm2yarn'); const versions = require('./versions.json'); const VersionsArchived = require('./versionsArchived.json'); const { dogfoodingPluginInstances, dogfoodingThemeInstances, } = require('./_dogfooding/dogfooding.config'); /** @type {Record>} */ const ConfigLocalized = require('./docusaurus.config.localized.json'); const ArchivedVersionsDropdownItems = Object.entries(VersionsArchived).splice( 0, 5, ); /** @param {string} version */ function isPrerelease(version) { return ( version.includes('alpha') || version.includes('beta') || version.includes('rc') ); } function getLastVersion() { const firstStableVersion = versions.find((version) => !isPrerelease(version)); return firstStableVersion ?? versions[0]; } // This probably only makes sense for the alpha/beta/rc phase, temporary function getNextVersionName() { return 'Canary'; /* const expectedPrefix = '2.0.0-rc.'; const lastReleasedVersion = versions[0]; if (!lastReleasedVersion || !lastReleasedVersion.includes(expectedPrefix)) { throw new Error( 'this code is only meant to be used during the 2.0 alpha/beta/rc phase.', ); } const version = parseInt(lastReleasedVersion.replace(expectedPrefix, ''), 10); return `${expectedPrefix}${version + 1}`; */ } // Artificial way to crash the SSR rendering and test errors // See website/_dogfooding/_pages tests/crashTest.tsx // Test with: DOCUSAURUS_CRASH_TEST=true yarn build:website:fast const crashTest = process.env.DOCUSAURUS_CRASH_TEST === 'true'; const isDev = process.env.NODE_ENV === 'development'; const isDeployPreview = !!process.env.NETLIFY && process.env.CONTEXT === 'deploy-preview'; // Netlify branch deploy like "docusaurus-v2" const isBranchDeploy = !!process.env.NETLIFY && process.env.CONTEXT === 'branch-deploy'; // Used to debug production build issues faster const isBuildFast = !!process.env.BUILD_FAST; const baseUrl = process.env.BASE_URL ?? '/'; // Special deployment for staging locales until they get enough translations // https://app.netlify.com/sites/docusaurus-i18n-staging // https://docusaurus-i18n-staging.netlify.app/ const isI18nStaging = process.env.I18N_STAGING === 'true'; const isVersioningDisabled = !!process.env.DISABLE_VERSIONING || isI18nStaging; const TwitterSvg = ''; const defaultLocale = 'en'; function getLocalizedConfigValue(/** @type {string} */ key) { const currentLocale = process.env.DOCUSAURUS_CURRENT_LOCALE ?? defaultLocale; const values = ConfigLocalized[key]; if (!values) { throw new Error(`Localized config key=${key} not found`); } const value = values[currentLocale] ?? values[defaultLocale]; if (!value) { throw new Error( `Localized value for config key=${key} not found for both currentLocale=${currentLocale} or defaultLocale=${defaultLocale}`, ); } return value; } /** @returns {Promise} */ module.exports = async function createConfigAsync() { return { title: 'Docusaurus', tagline: getLocalizedConfigValue('tagline'), organizationName: 'facebook', projectName: 'docusaurus', baseUrl, baseUrlIssueBanner: true, url: 'https://docusaurus.io', // Dogfood both settings: // - force trailing slashes for deploy previews // - avoid trailing slashes in prod trailingSlash: isDeployPreview, stylesheets: [ { href: '/katex/katex.min.css', type: 'text/css', }, ], i18n: { defaultLocale, locales: isDeployPreview || isBranchDeploy ? // Deploy preview and branch deploys: keep them fast! [defaultLocale] : isI18nStaging ? // Staging locales: https://docusaurus-i18n-staging.netlify.app/ [defaultLocale, 'ja'] : // Production locales [defaultLocale, 'fr', 'pt-BR', 'ko', 'zh-CN'], }, webpack: { jsLoader: (isServer) => ({ loader: require.resolve('swc-loader'), options: { jsc: { parser: { syntax: 'typescript', tsx: true, }, transform: { react: { runtime: 'automatic', }, }, target: 'es2017', }, module: { type: isServer ? 'commonjs' : 'es6', }, }, }), }, markdown: { mermaid: true, mdx1Compat: { // comments: false, }, preprocessor: ({filePath, fileContent}) => { // TODO temporary quick fix for https://github.com/facebook/docusaurus/issues/9084 fileContent = fileContent.replaceAll('