mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-22 13:37:05 +02:00
feat(core): faster transpiler option - siteConfig.future.experimental_faster.swcJsLoader
(#10435)
This commit is contained in:
parent
349a58453a
commit
418247ec87
30 changed files with 1298 additions and 847 deletions
Binary file not shown.
|
@ -13,7 +13,10 @@ import {isMatch} from 'picomatch';
|
|||
import commander from 'commander';
|
||||
import webpack from 'webpack';
|
||||
import {loadContext} from '@docusaurus/core/src/server/site';
|
||||
import {applyConfigureWebpack} from '@docusaurus/core/src/webpack/configure';
|
||||
import {
|
||||
applyConfigureWebpack,
|
||||
createConfigureWebpackUtils,
|
||||
} from '@docusaurus/core/src/webpack/configure';
|
||||
import {sortRoutes} from '@docusaurus/core/src/server/plugins/routeConfig';
|
||||
import {posixPath} from '@docusaurus/utils';
|
||||
import {normalizePluginOptions} from '@docusaurus/utils-validation';
|
||||
|
@ -22,7 +25,7 @@ import pluginContentDocs from '../index';
|
|||
import {toSidebarsProp} from '../props';
|
||||
import {DefaultSidebarItemsGenerator} from '../sidebars/generator';
|
||||
import {DisabledSidebars} from '../sidebars';
|
||||
import * as cliDocs from '../cli';
|
||||
import cliDocs from '../cli';
|
||||
import {validateOptions} from '../options';
|
||||
|
||||
import type {RouteConfig, Validate, Plugin} from '@docusaurus/types';
|
||||
|
@ -273,19 +276,23 @@ describe('simple website', () => {
|
|||
|
||||
const content = await plugin.loadContent?.();
|
||||
|
||||
const config = applyConfigureWebpack(
|
||||
plugin.configureWebpack as NonNullable<Plugin['configureWebpack']>,
|
||||
{
|
||||
const config = applyConfigureWebpack({
|
||||
configureWebpack: plugin.configureWebpack as NonNullable<
|
||||
Plugin['configureWebpack']
|
||||
>,
|
||||
config: {
|
||||
entry: './src/index.js',
|
||||
output: {
|
||||
filename: 'main.js',
|
||||
path: path.resolve(__dirname, 'dist'),
|
||||
},
|
||||
},
|
||||
false,
|
||||
undefined,
|
||||
isServer: false,
|
||||
utils: createConfigureWebpackUtils({
|
||||
siteConfig: {webpack: {jsLoader: 'babel'}},
|
||||
}),
|
||||
content,
|
||||
);
|
||||
});
|
||||
const errors = webpack.validate(config);
|
||||
expect(errors).toBeUndefined();
|
||||
});
|
||||
|
|
|
@ -53,7 +53,7 @@ async function createVersionedSidebarFile({
|
|||
}
|
||||
|
||||
// Tests depend on non-default export for mocking.
|
||||
export async function cliDocsVersionCommand(
|
||||
async function cliDocsVersionCommand(
|
||||
version: unknown,
|
||||
{id: pluginId, path: docsPath, sidebarPath}: PluginOptions,
|
||||
{siteDir, i18n}: LoadContext,
|
||||
|
@ -142,3 +142,17 @@ export async function cliDocsVersionCommand(
|
|||
|
||||
logger.success`name=${pluginIdLogPrefix}: version name=${version} created!`;
|
||||
}
|
||||
|
||||
// TODO try to remove this workaround
|
||||
// Why use a default export instead of named exports here?
|
||||
// This is only to make Jest mocking happy
|
||||
// After upgrading Jest/SWC we got this weird mocking error in extendCli tests
|
||||
// "spyOn: Cannot redefine property cliDocsVersionCommand"
|
||||
// I tried various workarounds, and it's the only one that worked :/
|
||||
// See also:
|
||||
// - https://pyk.sh/fixing-typeerror-cannot-redefine-property-x-error-in-jest-tests#heading-solution-2-using-barrel-imports
|
||||
// - https://github.com/aelbore/esbuild-jest/issues/26
|
||||
// - https://stackoverflow.com/questions/67872622/jest-spyon-not-working-on-index-file-cannot-redefine-property/69951703#69951703
|
||||
export default {
|
||||
cliDocsVersionCommand,
|
||||
};
|
||||
|
|
|
@ -40,7 +40,7 @@ import {
|
|||
readVersionsMetadata,
|
||||
toFullVersion,
|
||||
} from './versions';
|
||||
import {cliDocsVersionCommand} from './cli';
|
||||
import cliDocs from './cli';
|
||||
import {VERSIONS_JSON_FILE} from './constants';
|
||||
import {toGlobalDataVersion} from './globalData';
|
||||
import {
|
||||
|
@ -134,7 +134,7 @@ export default async function pluginContentDocs(
|
|||
.arguments('<version>')
|
||||
.description(commandDescription)
|
||||
.action((version: unknown) =>
|
||||
cliDocsVersionCommand(version, options, context),
|
||||
cliDocs.cliDocsVersionCommand(version, options, context),
|
||||
);
|
||||
},
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue