Skip to content

Commit e905b93

Browse files
authored
feat(core): add internal flag to skip bundling (#11156)
1 parent 59e9eb2 commit e905b93

2 files changed

Lines changed: 19 additions & 11 deletions

File tree

packages/docusaurus/src/commands/build/buildLocale.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export type BuildLocaleParams = {
3434
cliOptions: Partial<BuildCLIOptions>;
3535
};
3636

37+
const SkipBundling = process.env.DOCUSAURUS_SKIP_BUNDLING === 'true';
38+
3739
export async function buildLocale({
3840
siteDir,
3941
locale,
@@ -82,19 +84,25 @@ export async function buildLocale({
8284
// We also clear website/build dir
8385
// returns void, no useful result needed before compilation
8486
// See also https://github.com/facebook/docusaurus/pull/11037
85-
clearPath(outDir),
87+
SkipBundling ? undefined : clearPath(outDir),
8688
]),
8789
);
8890

89-
// Run webpack to build JS bundle (client) and static html files (server).
90-
await PerfLogger.async(`Bundling with ${props.currentBundler.name}`, () => {
91-
return compile({
92-
configs:
93-
// For hash router we don't do SSG and can skip the server bundle
94-
router === 'hash' ? [clientConfig] : [clientConfig, serverConfig],
95-
currentBundler: configureWebpackUtils.currentBundler,
91+
if (SkipBundling) {
92+
console.warn(
93+
`Skipping the Docusaurus bundling step because DOCUSAURUS_SKIP_BUNDLING='true'`,
94+
);
95+
} else {
96+
// Run webpack to build JS bundle (client) and static html files (server).
97+
await PerfLogger.async(`Bundling with ${props.currentBundler.name}`, () => {
98+
return compile({
99+
configs:
100+
// For hash router we don't do SSG and can skip the server bundle
101+
router === 'hash' ? [clientConfig] : [clientConfig, serverConfig],
102+
currentBundler: configureWebpackUtils.currentBundler,
103+
});
96104
});
97-
});
105+
}
98106

99107
const {collectedData} = await PerfLogger.async('SSG', () =>
100108
executeSSG({
@@ -231,7 +239,7 @@ async function getBuildServerConfig({
231239
async function cleanupServerBundle(serverBundlePath: string) {
232240
if (process.env.DOCUSAURUS_KEEP_SERVER_BUNDLE === 'true') {
233241
logger.warn(
234-
"Will NOT delete server bundle because DOCUSAURUS_KEEP_SERVER_BUNDLE is set to 'true'",
242+
"Will NOT delete server bundle because DOCUSAURUS_KEEP_SERVER_BUNDLE='true'",
235243
);
236244
} else {
237245
await PerfLogger.async('Deleting server bundle', async () => {

website/docusaurus.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ export default async function createConfigAsync() {
324324
showLastUpdateTime: true,
325325
} satisfies DocsOptions,
326326
],
327-
[
327+
!process.env.DOCUSAURUS_SKIP_BUNDLING && [
328328
'client-redirects',
329329
{
330330
fromExtensions: ['html'],

0 commit comments

Comments
 (0)