mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-03 00:39:45 +02:00
feat(core, mdx-loader): deduplicate MDX compilation - siteConfig.future.experimental_faster.mdxCrossCompilerCache
(#10479)
This commit is contained in:
parent
897ebbe3ca
commit
5bab0b5432
18 changed files with 333 additions and 151 deletions
|
@ -9,6 +9,7 @@ exports[`loadSiteConfig website with .cjs siteConfig 1`] = `
|
|||
"customFields": {},
|
||||
"future": {
|
||||
"experimental_faster": {
|
||||
"mdxCrossCompilerCache": false,
|
||||
"swcJsLoader": false,
|
||||
"swcJsMinimizer": false,
|
||||
},
|
||||
|
@ -74,6 +75,7 @@ exports[`loadSiteConfig website with ts + js config 1`] = `
|
|||
"customFields": {},
|
||||
"future": {
|
||||
"experimental_faster": {
|
||||
"mdxCrossCompilerCache": false,
|
||||
"swcJsLoader": false,
|
||||
"swcJsMinimizer": false,
|
||||
},
|
||||
|
@ -139,6 +141,7 @@ exports[`loadSiteConfig website with valid JS CJS config 1`] = `
|
|||
"customFields": {},
|
||||
"future": {
|
||||
"experimental_faster": {
|
||||
"mdxCrossCompilerCache": false,
|
||||
"swcJsLoader": false,
|
||||
"swcJsMinimizer": false,
|
||||
},
|
||||
|
@ -204,6 +207,7 @@ exports[`loadSiteConfig website with valid JS ESM config 1`] = `
|
|||
"customFields": {},
|
||||
"future": {
|
||||
"experimental_faster": {
|
||||
"mdxCrossCompilerCache": false,
|
||||
"swcJsLoader": false,
|
||||
"swcJsMinimizer": false,
|
||||
},
|
||||
|
@ -269,6 +273,7 @@ exports[`loadSiteConfig website with valid TypeScript CJS config 1`] = `
|
|||
"customFields": {},
|
||||
"future": {
|
||||
"experimental_faster": {
|
||||
"mdxCrossCompilerCache": false,
|
||||
"swcJsLoader": false,
|
||||
"swcJsMinimizer": false,
|
||||
},
|
||||
|
@ -334,6 +339,7 @@ exports[`loadSiteConfig website with valid TypeScript ESM config 1`] = `
|
|||
"customFields": {},
|
||||
"future": {
|
||||
"experimental_faster": {
|
||||
"mdxCrossCompilerCache": false,
|
||||
"swcJsLoader": false,
|
||||
"swcJsMinimizer": false,
|
||||
},
|
||||
|
@ -399,6 +405,7 @@ exports[`loadSiteConfig website with valid async config 1`] = `
|
|||
"customFields": {},
|
||||
"future": {
|
||||
"experimental_faster": {
|
||||
"mdxCrossCompilerCache": false,
|
||||
"swcJsLoader": false,
|
||||
"swcJsMinimizer": false,
|
||||
},
|
||||
|
@ -466,6 +473,7 @@ exports[`loadSiteConfig website with valid async config creator function 1`] = `
|
|||
"customFields": {},
|
||||
"future": {
|
||||
"experimental_faster": {
|
||||
"mdxCrossCompilerCache": false,
|
||||
"swcJsLoader": false,
|
||||
"swcJsMinimizer": false,
|
||||
},
|
||||
|
@ -533,6 +541,7 @@ exports[`loadSiteConfig website with valid config creator function 1`] = `
|
|||
"customFields": {},
|
||||
"future": {
|
||||
"experimental_faster": {
|
||||
"mdxCrossCompilerCache": false,
|
||||
"swcJsLoader": false,
|
||||
"swcJsMinimizer": false,
|
||||
},
|
||||
|
@ -603,6 +612,7 @@ exports[`loadSiteConfig website with valid siteConfig 1`] = `
|
|||
"favicon": "img/docusaurus.ico",
|
||||
"future": {
|
||||
"experimental_faster": {
|
||||
"mdxCrossCompilerCache": false,
|
||||
"swcJsLoader": false,
|
||||
"swcJsMinimizer": false,
|
||||
},
|
||||
|
|
|
@ -79,6 +79,7 @@ exports[`load loads props for site with custom i18n path 1`] = `
|
|||
"customFields": {},
|
||||
"future": {
|
||||
"experimental_faster": {
|
||||
"mdxCrossCompilerCache": false,
|
||||
"swcJsLoader": false,
|
||||
"swcJsMinimizer": false,
|
||||
},
|
||||
|
|
|
@ -48,6 +48,7 @@ describe('normalizeConfig', () => {
|
|||
experimental_faster: {
|
||||
swcJsLoader: true,
|
||||
swcJsMinimizer: true,
|
||||
mdxCrossCompilerCache: true,
|
||||
},
|
||||
experimental_storage: {
|
||||
type: 'sessionStorage',
|
||||
|
@ -743,6 +744,7 @@ describe('future', () => {
|
|||
experimental_faster: {
|
||||
swcJsLoader: true,
|
||||
swcJsMinimizer: true,
|
||||
mdxCrossCompilerCache: true,
|
||||
},
|
||||
experimental_storage: {
|
||||
type: 'sessionStorage',
|
||||
|
@ -1091,6 +1093,8 @@ describe('future', () => {
|
|||
it('accepts faster - full', () => {
|
||||
const faster: FasterConfig = {
|
||||
swcJsLoader: true,
|
||||
swcJsMinimizer: true,
|
||||
mdxCrossCompilerCache: true,
|
||||
};
|
||||
expect(
|
||||
normalizeConfig({
|
||||
|
@ -1202,6 +1206,7 @@ describe('future', () => {
|
|||
`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('swcJsMinimizer', () => {
|
||||
it('accepts - undefined', () => {
|
||||
const faster: Partial<FasterConfig> = {
|
||||
|
@ -1272,5 +1277,76 @@ describe('future', () => {
|
|||
`);
|
||||
});
|
||||
});
|
||||
|
||||
describe('mdxCrossCompilerCache', () => {
|
||||
it('accepts - undefined', () => {
|
||||
const faster: Partial<FasterConfig> = {
|
||||
mdxCrossCompilerCache: undefined,
|
||||
};
|
||||
expect(
|
||||
normalizeConfig({
|
||||
future: {
|
||||
experimental_faster: faster,
|
||||
},
|
||||
}),
|
||||
).toEqual(fasterContaining({mdxCrossCompilerCache: false}));
|
||||
});
|
||||
|
||||
it('accepts - true', () => {
|
||||
const faster: Partial<FasterConfig> = {
|
||||
mdxCrossCompilerCache: true,
|
||||
};
|
||||
expect(
|
||||
normalizeConfig({
|
||||
future: {
|
||||
experimental_faster: faster,
|
||||
},
|
||||
}),
|
||||
).toEqual(fasterContaining({mdxCrossCompilerCache: true}));
|
||||
});
|
||||
|
||||
it('accepts - false', () => {
|
||||
const faster: Partial<FasterConfig> = {
|
||||
mdxCrossCompilerCache: false,
|
||||
};
|
||||
expect(
|
||||
normalizeConfig({
|
||||
future: {
|
||||
experimental_faster: faster,
|
||||
},
|
||||
}),
|
||||
).toEqual(fasterContaining({mdxCrossCompilerCache: false}));
|
||||
});
|
||||
|
||||
it('rejects - null', () => {
|
||||
// @ts-expect-error: invalid
|
||||
const faster: Partial<FasterConfig> = {mdxCrossCompilerCache: 42};
|
||||
expect(() =>
|
||||
normalizeConfig({
|
||||
future: {
|
||||
experimental_faster: faster,
|
||||
},
|
||||
}),
|
||||
).toThrowErrorMatchingInlineSnapshot(`
|
||||
""future.experimental_faster.mdxCrossCompilerCache" must be a boolean
|
||||
"
|
||||
`);
|
||||
});
|
||||
|
||||
it('rejects - number', () => {
|
||||
// @ts-expect-error: invalid
|
||||
const faster: Partial<FasterConfig> = {mdxCrossCompilerCache: 42};
|
||||
expect(() =>
|
||||
normalizeConfig({
|
||||
future: {
|
||||
experimental_faster: faster,
|
||||
},
|
||||
}),
|
||||
).toThrowErrorMatchingInlineSnapshot(`
|
||||
""future.experimental_faster.mdxCrossCompilerCache" must be a boolean
|
||||
"
|
||||
`);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -44,12 +44,14 @@ export const DEFAULT_STORAGE_CONFIG: StorageConfig = {
|
|||
export const DEFAULT_FASTER_CONFIG: FasterConfig = {
|
||||
swcJsLoader: false,
|
||||
swcJsMinimizer: false,
|
||||
mdxCrossCompilerCache: false,
|
||||
};
|
||||
|
||||
// When using the "faster: true" shortcut
|
||||
export const DEFAULT_FASTER_CONFIG_TRUE: FasterConfig = {
|
||||
swcJsLoader: true,
|
||||
swcJsMinimizer: true,
|
||||
mdxCrossCompilerCache: true,
|
||||
};
|
||||
|
||||
export const DEFAULT_FUTURE_CONFIG: FutureConfig = {
|
||||
|
@ -217,6 +219,9 @@ const FASTER_CONFIG_SCHEMA = Joi.alternatives()
|
|||
swcJsMinimizer: Joi.boolean().default(
|
||||
DEFAULT_FASTER_CONFIG.swcJsMinimizer,
|
||||
),
|
||||
mdxCrossCompilerCache: Joi.boolean().default(
|
||||
DEFAULT_FASTER_CONFIG.mdxCrossCompilerCache,
|
||||
),
|
||||
}),
|
||||
Joi.boolean()
|
||||
.required()
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
import path from 'path';
|
||||
import {fromPartial} from '@total-typescript/shoehorn';
|
||||
import {loadPlugins, reloadPlugin} from '../plugins';
|
||||
import {DEFAULT_FUTURE_CONFIG} from '../../configValidation';
|
||||
import type {LoadContext, Plugin, PluginConfig} from '@docusaurus/types';
|
||||
|
||||
async function testLoad({
|
||||
|
@ -27,6 +28,7 @@ async function testLoad({
|
|||
siteConfig: {
|
||||
baseUrl: '/',
|
||||
trailingSlash: true,
|
||||
future: DEFAULT_FUTURE_CONFIG,
|
||||
themeConfig: {},
|
||||
staticDirectories: [],
|
||||
presets: [],
|
||||
|
|
|
@ -80,6 +80,8 @@ export async function createMDXFallbackPlugin({
|
|||
siteConfig,
|
||||
}: LoadContext): Promise<InitializedPlugin> {
|
||||
const mdxLoaderItem = await createMDXLoaderItem({
|
||||
useCrossCompilerCache:
|
||||
siteConfig.future.experimental_faster.mdxCrossCompilerCache,
|
||||
admonitions: true,
|
||||
staticDirs: siteConfig.staticDirectories.map((dir) =>
|
||||
path.resolve(siteDir, dir),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue