-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
132 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
import webpack from 'webpack'; | ||
import WebpackBar from 'webpackbar'; | ||
import MiniCssExtractPlugin from 'mini-css-extract-plugin'; | ||
import CopyWebpackPlugin from 'copy-webpack-plugin'; | ||
import logger from '@docusaurus/logger'; | ||
import type {CurrentBundler, DocusaurusConfig} from '@docusaurus/types'; | ||
|
||
// We inject a site config slice because the Rspack flag might change place | ||
type SiteConfigSlice = { | ||
future: { | ||
experimental_faster: Pick< | ||
DocusaurusConfig['future']['experimental_faster'], | ||
'rspackBundler' | ||
>; | ||
}; | ||
}; | ||
|
||
function isRspack(siteConfig: SiteConfigSlice): boolean { | ||
return siteConfig.future.experimental_faster.rspackBundler; | ||
} | ||
|
||
export async function getCurrentBundler({ | ||
siteConfig, | ||
}: { | ||
siteConfig: SiteConfigSlice; | ||
}): Promise<CurrentBundler> { | ||
if (isRspack(siteConfig)) { | ||
// TODO add support for Rspack | ||
logger.error( | ||
'Rspack bundler is not supported yet, will use Webpack instead', | ||
); | ||
} | ||
return { | ||
name: 'webpack', | ||
instance: webpack, | ||
}; | ||
} | ||
|
||
export async function getCSSExtractPlugin({ | ||
currentBundler, | ||
}: { | ||
currentBundler: CurrentBundler; | ||
}): Promise<typeof MiniCssExtractPlugin> { | ||
if (currentBundler.name === 'rspack') { | ||
throw new Error('Rspack bundler is not supported yet'); | ||
} | ||
return MiniCssExtractPlugin; | ||
} | ||
|
||
export async function getCopyPlugin({ | ||
currentBundler, | ||
}: { | ||
currentBundler: CurrentBundler; | ||
}): Promise<typeof CopyWebpackPlugin> { | ||
if (currentBundler.name === 'rspack') { | ||
throw new Error('Rspack bundler is not supported yet'); | ||
} | ||
// https://github.com/webpack-contrib/copy-webpack-plugin | ||
return CopyWebpackPlugin; | ||
} | ||
|
||
export async function getProgressBarPlugin({ | ||
currentBundler, | ||
}: { | ||
currentBundler: CurrentBundler; | ||
}): Promise<typeof WebpackBar> { | ||
if (currentBundler.name === 'rspack') { | ||
class CustomRspackProgressPlugin extends currentBundler.instance | ||
.ProgressPlugin { | ||
constructor({name}: {name: string}) { | ||
// TODO add support for color | ||
// Unfortunately the rspack.ProgressPlugin does not have a name option | ||
// See https://rspack.dev/plugins/webpack/progress-plugin | ||
// @ts-expect-error: adapt Rspack ProgressPlugin constructor | ||
super({prefix: name}); | ||
} | ||
} | ||
return CustomRspackProgressPlugin as typeof WebpackBar; | ||
} | ||
|
||
return WebpackBar; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,7 +92,6 @@ | |
"semver": "^7.5.4", | ||
"serve-handler": "npm:@docusaurus/[email protected]", | ||
"shelljs": "^0.8.5", | ||
"terser-webpack-plugin": "^5.3.10", | ||
"tslib": "^2.6.0", | ||
"update-notifier": "^6.0.2", | ||
"url-loader": "^4.1.1", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters