Skip to content

Commit aa4f948

Browse files
authored
feat: RSpack to improve performance. (#4798)
* feat: rspack integration. * fixed client side debugging. * Rename zbuild and zserve scripts to build and serve * fixed lock file.
1 parent 2013328 commit aa4f948

File tree

10 files changed

+333
-724
lines changed

10 files changed

+333
-724
lines changed

.github/workflows-src/partials/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# v5 build
77
- uses: actions/cache@v4
88
id: site-cache
9-
name: Load webpack cache
9+
name: Load rspack cache
1010
with:
1111
path: "packages/documentation-site/.cache"
1212
key: ${{ runner.os }}-${{ hashFiles('yarn.lock') }}

.github/workflows/pr-preview.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
# build
2525
- uses: actions/cache@v4
2626
id: site-cache
27-
name: Load webpack cache
27+
name: Load rspack cache
2828
with:
2929
path: "packages/documentation-site/.cache"
3030
key: ${{ runner.os }}-${{ hashFiles('yarn.lock') }}

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
"@patternfly/react-code-editor": "^6.4.0",
3939
"@patternfly/react-core": "^6.5.0-prerelease.1",
4040
"@patternfly/react-table": "^6.5.0-prerelease.1",
41+
"@rspack/cli": "^1.5.6",
42+
"@rspack/core": "^1.5.6",
43+
"@rspack/dev-server": "^1.1.4",
4144
"glob": "^8.1.0",
4245
"lerna": "^6.4.1",
4346
"react": "^18",

packages/documentation-framework/package.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@
1818
"babel-loader": "^9.1.3",
1919
"camelcase-css": "2.0.1",
2020
"chokidar": "4.0.0",
21-
"clean-webpack-plugin": "4.0.0",
2221
"codesandbox": "2.2.3",
2322
"commander": "4.1.1",
24-
"copy-webpack-plugin": "13.0.0",
2523
"css-loader": "6.7.3",
2624
"detab": "2.0.3",
2725
"express": "4.21.2",
@@ -37,7 +35,6 @@
3735
"js-yaml": "3.14.0",
3836
"mdast-util-to-hast": "9.1.1",
3937
"mdurl": "1.0.1",
40-
"mini-css-extract-plugin": "2.7.5",
4138
"null-loader": "4.0.1",
4239
"parse-entities": "2.0.0",
4340
"path-browserify": "1.0.1",
@@ -64,9 +61,7 @@
6461
"unist-util-visit": "2.0.3",
6562
"url-loader": "4.1.0",
6663
"vfile-reporter": "6.0.1",
67-
"webpack": "5.94.0",
6864
"webpack-bundle-analyzer": "4.10.2",
69-
"webpack-cli": "5.0.1",
7065
"webpack-dev-server": "5.2.2",
7166
"webpack-merge": "5.8.0"
7267
},

packages/documentation-framework/scripts/cli/build.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
const path = require('path');
22
const { fork } = require('child_process');
3-
const webpack = require('webpack');
3+
const rspack = require('@rspack/core');
44
const { generate } = require('./generate');
55
const { getConfig } = require('./helpers');
66

77
async function buildWebpack(webpackConfig) {
88
let compiler;
99
try {
10-
compiler = webpack(webpackConfig);
10+
compiler = rspack(webpackConfig);
1111
} catch (err) {
1212
if (err.name === "WebpackOptionsValidationError") {
1313
console.error(err.message);

packages/documentation-framework/scripts/cli/start.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
const WebpackDevServer = require('webpack-dev-server');
2-
const webpack = require('webpack');
1+
const { RspackDevServer }= require('@rspack/dev-server');
2+
const rspack = require('@rspack/core');
33
const clientConfig = require('../webpack/webpack.client.config');
44
const { generate } = require('./generate');
55
const { getConfig } = require('./helpers');
66
const { watchMD } = require('../md/parseMD');
77

8-
function startWebpackDevServer(webpackConfig) {
8+
function startDevServer(webpackConfig) {
99
webpackConfig.devServer.static = false;
1010
const { port } = webpackConfig.devServer;
11-
const compiler = webpack(webpackConfig);
12-
const server = new WebpackDevServer(webpackConfig.devServer, compiler);
11+
const compiler = rspack(webpackConfig);
12+
const server = new RspackDevServer(webpackConfig.devServer, compiler);
1313

1414
(async () => {
1515
await server.start();
@@ -20,9 +20,9 @@ function startWebpackDevServer(webpackConfig) {
2020
async function start(options) {
2121
generate(options, true);
2222
const webpackClientConfig = await clientConfig(null, { mode: 'development', ...getConfig(options) });
23-
console.log('start webpack-dev-server');
23+
console.log('start rspack-dev-server');
2424
watchMD();
25-
startWebpackDevServer(webpackClientConfig);
25+
startDevServer(webpackClientConfig);
2626
}
2727

2828
module.exports = {

packages/documentation-framework/scripts/webpack/webpack.base.config.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
const path = require('path');
2-
const webpack = require('webpack');
3-
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
4-
const CopyWebpackPlugin = require('copy-webpack-plugin');
2+
const rspack = require('@rspack/core');
53

64
module.exports = (_env, argv) => {
75
const {
@@ -121,10 +119,10 @@ module.exports = (_env, argv) => {
121119
modules: module.paths
122120
},
123121
plugins: [
124-
new webpack.ProvidePlugin({
122+
new rspack.ProvidePlugin({
125123
process: 'process/browser'
126124
}),
127-
new webpack.DefinePlugin({
125+
new rspack.DefinePlugin({
128126
'process.env.NODE_ENV': JSON.stringify(mode),
129127
'process.env.googleAnalyticsID': JSON.stringify(isProd ? googleAnalyticsID : ''),
130128
'process.env.algolia': JSON.stringify(algolia),
@@ -142,7 +140,7 @@ module.exports = (_env, argv) => {
142140
'process.env.prnum': JSON.stringify(process.env.CIRCLE_PR_NUMBER || process.env.PR_NUMBER || ''),
143141
'process.env.prurl': JSON.stringify(process.env.CIRCLE_PULL_REQUEST || '')
144142
}),
145-
new CopyWebpackPlugin({
143+
new rspack.CopyRspackPlugin({
146144
patterns: [{ from: path.join(__dirname, '../../assets'), to: 'assets' }]
147145
})
148146
],

packages/documentation-framework/scripts/webpack/webpack.client.config.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ const path = require('path');
22
const fs = require('fs');
33
const { merge } = require('webpack-merge');
44
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
5-
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
6-
const TerserPlugin = require('terser-webpack-plugin');
7-
const CopyPlugin = require('copy-webpack-plugin');
8-
const webpack = require('webpack');
5+
const rspack = require('@rspack/core');
96
const baseConfig = require('./webpack.base.config');
107
const { getHtmlWebpackPlugins } = require('./getHtmlWebpackPlugins');
118

@@ -74,7 +71,9 @@ const clientConfig = async (env, argv) => {
7471
},
7572
minimize: isProd ? true : false,
7673
minimizer: [
77-
new TerserPlugin(),
74+
new rspack.SwcJsMinimizerRspackPlugin({
75+
// options
76+
}),
7877
],
7978
runtimeChunk: 'single',
8079
},
@@ -85,7 +84,7 @@ const clientConfig = async (env, argv) => {
8584
exclude: reactCSSRegex,
8685
use: [
8786
{
88-
loader: MiniCssExtractPlugin.loader
87+
loader: rspack.CssExtractRspackPlugin.loader
8988
},
9089
{
9190
loader: 'css-loader'
@@ -109,14 +108,14 @@ const clientConfig = async (env, argv) => {
109108
]
110109
},
111110
plugins: [
112-
new webpack.DefinePlugin({
111+
new rspack.DefinePlugin({
113112
'process.env.PRERENDER': false,
114113
}),
115-
new MiniCssExtractPlugin(!isProd ? {} : {
114+
new rspack.CssExtractRspackPlugin(!isProd ? {} : {
116115
filename: 'css/[name].[contenthash].css',
117116
chunkFilename: 'css/[name].[contenthash].css',
118117
}),
119-
new CopyPlugin({
118+
new rspack.CopyRspackPlugin({
120119
patterns: [
121120
// versions.json will later be copied to the root www dir
122121
{ from: path.join(__dirname, '../../versions.json'), to: 'versions.json' },

packages/documentation-framework/scripts/webpack/webpack.server.config.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
const path = require('path');
2-
const webpack = require('webpack');
2+
const rspack = require('@rspack/core');
33
const { merge } = require('webpack-merge');
44
const baseConfig = require('./webpack.base.config');
5-
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
65
const reactCSSRegex = /(react-[\w-]+\/dist|react-styles\/css)\/.*\.css$/;
76

87
const serverConfig = async (env, argv) => {
@@ -14,7 +13,7 @@ const serverConfig = async (env, argv) => {
1413
},
1514
target: 'node', // Load chunks using require
1615
plugins: [
17-
new webpack.DefinePlugin({
16+
new rspack.DefinePlugin({
1817
'process.env.PRERENDER': true // In app.js don't call ReactDOM.render
1918
}),
2019
],

0 commit comments

Comments
 (0)