Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): Replace Webpack with Rspack - siteConfig.future.experimental_faster.rspackBundler #10402

Merged
merged 65 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
0dc5661
Rspack POC
slorber Aug 14, 2024
b1f4ae2
fix scripts
slorber Aug 14, 2024
ca7fefc
temp remove DefinePlugin
slorber Aug 14, 2024
127845d
fix pwa EnvironmentPlugin + CopyRspackPlugin
slorber Aug 14, 2024
c13d987
Add Rsdoctor plugin
slorber Aug 15, 2024
d08a465
remove RSDOCTOR by defaulkt
slorber Aug 15, 2024
2cfe4cd
remove useless exit + use Rspack minifiers
slorber Aug 15, 2024
8a2ab67
builtin:swc-loader
slorber Aug 15, 2024
6ec8d65
remove alias CssExtractRspackPlugin as MiniCssExtractPlugin
slorber Aug 16, 2024
64fdfcf
remove alias CssExtractRspackPlugin as MiniCssExtractPlugin
slorber Aug 16, 2024
4138492
Revert "remove alias CssExtractRspackPlugin as MiniCssExtractPlugin"
slorber Aug 16, 2024
486ee81
use LightningCssMinimizerRspackPlugin
slorber Aug 16, 2024
69f7d43
use RsdoctorRspackMultiplePlugin
slorber Aug 22, 2024
cbddd79
merge from main
slorber Sep 6, 2024
2e27a8a
upgrade and fix Rsdoctor?
slorber Sep 6, 2024
dacc090
upgrade Rspack to v1 stable
slorber Sep 6, 2024
fc9576b
Try to restore ChunkAssetPlugin for preloading
slorber Sep 6, 2024
a76cb73
Merge branch 'main' into slorber/poc-rspack
slorber Sep 10, 2024
b5c267a
Rspack 1.0.4
slorber Sep 10, 2024
2fff52f
damn, ChunkAssetPlugin still doesn't work
slorber Sep 10, 2024
456cde8
Merge branch 'main' into slorber/poc-rspack
slorber Sep 13, 2024
318c2df
fix merge issues
slorber Sep 13, 2024
3b5dbe5
try to fix Rspack build
slorber Sep 13, 2024
5e3fe51
add todo
slorber Sep 13, 2024
68b4bf6
add todo + disable gca
slorber Sep 13, 2024
fc08c5d
make it work
slorber Sep 13, 2024
e8272c4
build perf, log current bundler name
slorber Sep 13, 2024
0cee6bf
add RspackJsLoaderFactory
slorber Sep 13, 2024
6261ab5
simplify Rspack js loader
slorber Sep 13, 2024
bf2ad51
simplify Rspack js loader
slorber Sep 13, 2024
a06b194
fix lint error + wire rspack minimizer properly
slorber Sep 13, 2024
c8dc795
fix minimizer
slorber Sep 13, 2024
3b6987d
fix theme configureWebpack
slorber Sep 13, 2024
200ced7
fix Prism bundle size increase
slorber Sep 13, 2024
b4469fe
refactor: apply lint autofix
slorber Sep 13, 2024
0739fce
empty
slorber Sep 13, 2024
a608e88
Merge branch 'main' into slorber/poc-rspack
slorber Sep 26, 2024
5de89ab
handle merge conflicts
slorber Sep 26, 2024
d6b34a9
rspack 1.0.7
slorber Sep 26, 2024
c4881e7
attempt to restore ChunkAssetPlugin
slorber Sep 26, 2024
402d3ef
temp disable ChunkAssetPlugin
slorber Sep 26, 2024
74ddd14
refactor: apply lint autofix
slorber Sep 26, 2024
628980e
empty
slorber Sep 26, 2024
c66bfb4
fix createJsLoaderFactory test
slorber Sep 26, 2024
cb84db1
remove Rspack config validation errors
slorber Sep 26, 2024
3a202df
Use Rspack canary, restore ChunkAssetPlugin
slorber Sep 26, 2024
128bfd6
Merge branch 'main' into slorber/poc-rspack
slorber Sep 27, 2024
5bb213e
re-add missing rspack dep + fix lockfile
slorber Sep 27, 2024
4eacf9f
Wire browserslist to LightningCSS built-in targets
slorber Sep 27, 2024
e23b63e
restore dynamic require usage
slorber Sep 30, 2024
097ed54
Rspack 1.0.8
slorber Sep 30, 2024
1c48869
Merge branch 'main' into slorber/poc-rspack
slorber Oct 3, 2024
8093a21
Add useful comment for getBrowserslistQueries
slorber Oct 3, 2024
9eebd7f
Merge branch 'main' into slorber/poc-rspack
slorber Oct 3, 2024
4f40e3b
Merge branch 'main' into slorber/poc-rspack
slorber Oct 4, 2024
961a940
Update Rspack
slorber Oct 10, 2024
a26613e
Merge branch 'main' into slorber/poc-rspack
slorber Oct 10, 2024
2cdb41e
Fix rsdoctor skipLibCheck issue
slorber Oct 10, 2024
901be76
upgrade Rsdoctor
slorber Oct 10, 2024
ab0e856
perf log
slorber Oct 10, 2024
c9d3afa
remove temp gca() workaround
slorber Oct 10, 2024
b339274
diff
slorber Oct 10, 2024
d1df260
add SwcJsMinimizerRspackPlugin config
slorber Oct 10, 2024
b913a17
comment
slorber Oct 10, 2024
b02fb3e
use shared conservative swc minifier options
slorber Oct 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/docusaurus-plugin-pwa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"core-js": "^3.31.1",
"terser-webpack-plugin": "^5.3.9",
"tslib": "^2.6.0",
"webpack": "^5.88.1",
"webpack": "npm:@rspack/[email protected]",
"webpack-merge": "^5.9.0",
"webpackbar": "^5.0.2",
"workbox-build": "^7.0.0",
Expand Down
26 changes: 15 additions & 11 deletions packages/docusaurus-plugin-pwa/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import path from 'path';
import webpack, {type Configuration} from 'webpack';
import webpack, {rspack, type Configuration} from 'webpack';
import WebpackBar from 'webpackbar';
import Terser from 'terser-webpack-plugin';
import {injectManifest} from 'workbox-build';
Expand Down Expand Up @@ -89,18 +89,22 @@ export default function pluginPWA(
});
},

// @ts-expect-error: todo fix
configureWebpack(config) {
return {
plugins: [
new webpack.EnvironmentPlugin({
PWA_DEBUG: debug,
PWA_SERVICE_WORKER_URL: path.posix.resolve(
`${(config.output?.publicPath as string) || '/'}`,
'sw.js',
),
PWA_OFFLINE_MODE_ACTIVATION_STRATEGIES:
offlineModeActivationStrategies,
}),
new rspack.EnvironmentPlugin(
// @ts-expect-error: todo fix
{
PWA_DEBUG: debug,
PWA_SERVICE_WORKER_URL: path.posix.resolve(
`${(config.output?.publicPath as string) || '/'}`,
'sw.js',
),
PWA_OFFLINE_MODE_ACTIVATION_STRATEGIES:
offlineModeActivationStrategies,
},
),
],
};
},
Expand Down Expand Up @@ -157,7 +161,7 @@ export default function pluginPWA(
],
},
plugins: [
new webpack.EnvironmentPlugin({
new rspack.EnvironmentPlugin({
// Fallback value required with Webpack 5
PWA_SW_CUSTOM: swCustom ?? '',
}),
Expand Down
5 changes: 5 additions & 0 deletions packages/docusaurus-theme-classic/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ import type webpack from 'webpack';
const requireFromDocusaurusCore = createRequire(
require.resolve('@docusaurus/core/package.json'),
);
/*
const ContextReplacementPlugin = requireFromDocusaurusCore(
'webpack/lib/ContextReplacementPlugin',
) as typeof webpack.ContextReplacementPlugin;
*/

function getInfimaCSSFile(direction: string) {
return `infima/dist/css/default/default${
Expand Down Expand Up @@ -99,10 +101,13 @@ export default function themeClassic(
// This allows better optimization by only bundling those components
// that the user actually needs, because the modules are dynamically
// required and can't be known during compile time.
/*
ContextReplacementPlugin is not supported yet, tracked here https://github.com/web-infra-dev/rspack/issues/7474
new ContextReplacementPlugin(
/prismjs[\\/]components$/,
new RegExp(`^./(${prismLanguages})$`),
),
*/
],
};
},
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"tslib": "^2.6.0",
"update-notifier": "^6.0.2",
"url-loader": "^4.1.1",
"webpack": "^5.88.1",
"webpack": "npm:@rspack/[email protected]",
"webpack-bundle-analyzer": "^4.9.0",
"webpack-dev-server": "^4.15.1",
"webpack-merge": "^5.9.0",
Expand Down
26 changes: 14 additions & 12 deletions packages/docusaurus/src/client/docusaurus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,20 @@ const prefetch: Docusaurus['prefetch'] = (

// Prefetch all webpack chunk assets file needed.
return Promise.all(
chunkNamesNeeded.map((chunkName) => {
// "__webpack_require__.gca" is injected by ChunkAssetPlugin. Pass it
// the name of the chunk you want to load and it will return its URL.
// eslint-disable-next-line camelcase
const chunkAsset = __webpack_require__.gca(chunkName);

// In some cases, webpack might decide to optimize further, leading to
// the chunk assets being merged to another chunk. In this case, we can
// safely filter it out and don't need to load it.
if (chunkAsset && !chunkAsset.includes('undefined')) {
return prefetchHelper(chunkAsset);
}
chunkNamesNeeded.map((/* chunkName */) => {
/* TODO ChunkAssetPlugin not working now

// "__webpack_require__.gca" is injected by ChunkAssetPlugin. Pass it
// the name of the chunk you want to load and it will return its URL.
// eslint-disable-next-line camelcase
const chunkAsset = __webpack_require__.gca(chunkName);
// In some cases, webpack might decide to optimize further, leading to
// the chunk assets being merged to another chunk. In this case, we can
// safely filter it out and don't need to load it.
if (chunkAsset && !chunkAsset.includes('undefined')) {
return prefetchHelper(chunkAsset);
}
*/
return Promise.resolve();
}),
);
Expand Down
4 changes: 4 additions & 0 deletions packages/docusaurus/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,12 @@ export async function build(
logger.info`Use code=${'npm run serve'} command to test your build locally.`;
}

/*
// TODO do we really need this historical forceTerminate exit???
if (forceTerminate && isLastLocale && !cliOptions.bundleAnalyzer) {
process.exit(0);
}
*/
}),
);
}
Expand Down Expand Up @@ -353,6 +355,7 @@ async function getBuildClientConfig({
plugins,
config,
isServer: false,
// @ts-expect-error: todo fix
jsLoader: props.siteConfig.webpack?.jsLoader,
});
return {clientConfig: config, clientManifestPath: result.clientManifestPath};
Expand All @@ -368,6 +371,7 @@ async function getBuildServerConfig({props}: {props: Props}) {
plugins,
config,
isServer: true,
// @ts-expect-error: todo fix
jsLoader: props.siteConfig.webpack?.jsLoader,
});
return {serverConfig: config, serverBundlePath: result.serverBundlePath};
Expand Down
6 changes: 4 additions & 2 deletions packages/docusaurus/src/commands/start/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import path from 'path';
import merge from 'webpack-merge';
import webpack from 'webpack';
import {rspack} from 'webpack';
import logger from '@docusaurus/logger';
import WebpackDevServer from 'webpack-dev-server';
import evalSourceMapMiddleware from 'react-dev-utils/evalSourceMapMiddleware';
Expand Down Expand Up @@ -139,6 +139,7 @@ async function getStartClientConfig({
plugins,
config,
isServer: false,
// @ts-expect-error: todo fix
jsLoader: siteConfig.webpack?.jsLoader,
});
return config;
Expand All @@ -159,7 +160,7 @@ export async function createWebpackDevServer({
poll: cliOptions.poll,
});

const compiler = webpack(config);
const compiler = rspack(config);
registerWebpackE2ETestHook(compiler);

const defaultDevServerConfig = await createDevServerConfig({
Expand All @@ -174,5 +175,6 @@ export async function createWebpackDevServer({
[defaultDevServerConfig, config.devServer].filter(Boolean),
);

// @ts-expect-error: todo fix
return new WebpackDevServer(devServerConfig, compiler);
}
84 changes: 83 additions & 1 deletion packages/docusaurus/src/webpack/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

import fs from 'fs-extra';
import path from 'path';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
// import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import {CssExtractRspackPlugin as MiniCssExtractPlugin} from 'webpack';

import {md5Hash, getFileLoaderUtils} from '@docusaurus/utils';
import {
getCustomizableJSLoader,
Expand Down Expand Up @@ -87,6 +89,7 @@ export async function createBaseConfig({
return {
mode,
name,
// @ts-expect-error: TODO fix this
cache: {
type: 'filesystem',
// Can we share the same cache across locales?
Expand Down Expand Up @@ -131,6 +134,7 @@ export async function createBaseConfig({
},
devtool: isProd ? undefined : 'eval-cheap-module-source-map',
resolve: {
// @ts-expect-error: TODO fix this
unsafeCache: false, // Not enabled, does not seem to improve perf much
extensions: ['.wasm', '.mjs', '.js', '.jsx', '.ts', '.tsx', '.json'],
symlinks: true, // See https://github.com/facebook/docusaurus/issues/3272
Expand Down Expand Up @@ -202,24 +206,98 @@ export async function createBaseConfig({
},
module: {
rules: [
// @ts-expect-error: TODO fix this
fileLoaderUtils.rules.images(),
// @ts-expect-error: TODO fix this
fileLoaderUtils.rules.fonts(),
// @ts-expect-error: TODO fix this
fileLoaderUtils.rules.media(),
// @ts-expect-error: TODO fix this
fileLoaderUtils.rules.svg(),
// @ts-expect-error: TODO fix this
fileLoaderUtils.rules.otherAssets(),

/*
{
test: /\.[jt]sx?$/i,
exclude: excludeJS,
use: [
// @ts-expect-error: TODO fix this
getCustomizableJSLoader(siteConfig.webpack?.jsLoader)({
isServer,
babelOptions: await getCustomBabelConfigFilePath(siteDir),
}),
],
},
*/

// TODO do we really need 3 different loaders for js, ts, tsx?
{
test: /\.jsx?$/,
exclude: excludeJS,
use: {
loader: 'builtin:swc-loader',
options: {
jsc: {
parser: {
syntax: 'ecmascript',
jsx: true,
},
transform: {
react: {
runtime: 'automatic',
},
},
},
},
},
},

{
test: /\.tsx$/,
exclude: excludeJS,
use: {
loader: 'builtin:swc-loader',
options: {
jsc: {
parser: {
syntax: 'typescript',
tsx: true,
},
transform: {
react: {
runtime: 'automatic',
},
},
},
},
},
},
{
test: /\.ts$/,
exclude: excludeJS,
use: {
loader: 'builtin:swc-loader',
options: {
jsc: {
parser: {
syntax: 'typescript',
tsx: false,
},
transform: {
react: {
runtime: 'automatic',
},
},
},
},
},
},

{
test: CSS_REGEX,
exclude: CSS_MODULE_REGEX,
// @ts-expect-error: TODO fix this
use: getStyleLoaders(isServer, {
importLoaders: 1,
sourceMap: !isProd,
Expand All @@ -229,6 +307,7 @@ export async function createBaseConfig({
// using the extension .module.css
{
test: CSS_MODULE_REGEX,
// @ts-expect-error: TODO fix this
use: getStyleLoaders(isServer, {
modules: {
localIdentName: isProd
Expand All @@ -242,6 +321,9 @@ export async function createBaseConfig({
},
],
},
experiments: {
css: false,
},
plugins: [
new MiniCssExtractPlugin({
filename: isProd
Expand Down
11 changes: 7 additions & 4 deletions packages/docusaurus/src/webpack/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import path from 'path';
import merge from 'webpack-merge';
import WebpackBar from 'webpackbar';
import webpack from 'webpack';
import webpack, {rspack} from 'webpack';
import {BundleAnalyzerPlugin} from 'webpack-bundle-analyzer';
import ReactLoadableSSRAddon from 'react-loadable-ssr-addon-v5-slorber';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import {createBaseConfig} from './base';
import ChunkAssetPlugin from './plugins/ChunkAssetPlugin';
// import ChunkAssetPlugin from './plugins/ChunkAssetPlugin';
import CleanWebpackPlugin from './plugins/CleanWebpackPlugin';
import ForceTerminatePlugin from './plugins/ForceTerminatePlugin';
import {createStaticDirectoriesCopyPlugin} from './plugins/StaticDirectoriesCopyPlugin';
Expand Down Expand Up @@ -42,14 +42,17 @@ async function createBaseClientConfig({
runtimeChunk: true,
},
plugins: [
new webpack.DefinePlugin({
new rspack.DefinePlugin({
'process.env.HYDRATE_CLIENT_ENTRY': JSON.stringify(hydrate),
}),
new ChunkAssetPlugin(),

// new ChunkAssetPlugin(),

// Show compilation progress bar and build time.
new WebpackBar({
name: 'Client',
}),

await createStaticDirectoriesCopyPlugin({props}),
].filter(Boolean),
});
Expand Down
3 changes: 3 additions & 0 deletions packages/docusaurus/src/webpack/configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@ export function applyConfigureWebpack(
): Configuration {
// Export some utility functions
const utils: ConfigureWebpackUtils = {
// @ts-expect-error: todo fix
getStyleLoaders,
// @ts-expect-error: todo fix
getJSLoader: getCustomizableJSLoader(jsLoader),
};
if (typeof configureWebpack === 'function') {
const {mergeStrategy, ...res} =
// @ts-expect-error: todo fix
configureWebpack(config, isServer, utils, content) ?? {};
const customizeRules = mergeStrategy ?? {};
return mergeWithCustomize({
Expand Down
Loading
Loading