#
Migrate from webpack
To migrate from @workleap/webpack-configs to @workleap/rsbuild-configs, execute the following steps 👇
#
Update packages
Open a terminal at the root of the web application project and install the following packages:
pnpm add -D @workleap/rsbuild-configs @rsbuild/core @rspack/core
Then, using the same terminal, remove the following packages:
pnpm remove @workleap/webpack-configs @swc/core @swc/helpers @workleap/swc-configs webpack webpack-cli webpack-dev-server @workleap/postcss-configs postcss
If your web application project uses SWC for tests, you may want to keep the @swc/core and @workleap/swc-configs packages.
#
Update files
web-project
├── public
├──── index.html --> U
├── webpack.dev.js --> rsbuild.dev.ts
├── webpack.build.js --> rsbuild.build.ts
├── postcss.config.ts --> X
├── swc.build.js --> X
├── swc.dev.js --> X
├── package.json
#
webpack.dev.js
Rename the file from webpack.dev.js to rsbuild.dev.ts.
Then, open the rsbuild.build.ts file and and apply the following changes:
- Replace
"@workleap/webpack-configs"for"@workleap/rsbuild-configs". - Remove
import { swcConfig } from "./swc.build.js". - Remove the argument of the
defineDevConfigfunction. - Remove
// @ts-check.
Before:
// @ts-check
import { defineDevConfig } from "@workleap/webpack-configs";
import { swcConfig } from "./swc.dev.js";
export default defineDevConfig(swcConfig);
After:
import { defineDevConfig } from "@workleap/rsbuild-configs";
export default defineDevConfig();
#
webpack.build.js
Rename the file from webpack.build.js to rsbuild.build.ts.
Then, open the rsbuild.build.ts file and apply the following changes:
- Replace
"@workleap/webpack-configs"for"@workleap/rsbuild-configs". - Remove
import { swcConfig } from "./swc.build.js". - Remove the argument of the
defineBuildConfigfunction. - Remove
// @ts-check.
Before:
// @ts-check
import { defineBuildConfig } from "@workleap/webpack-configs";
import { swcConfig } from "./swc.build.js";
export default defineBuildConfig(swcConfig);
After:
import { defineBuildConfig } from "@workleap/rsbuild-configs";
export default defineBuildConfig();
#
postcss.config.ts
Delete the postcss.config.ts file.
#
swc.build.js
Delete the swc.build.js file.
#
swc.dev.js
Delete the swc.dev.js file.
#
index.html
Replace <%=webpackConfig.output.publicPath%> by <%=assetPrefix%>/ (the / is important).
Before:
<!DOCTYPE html>
<html>
<head>
<link href="<%=webpackConfig.output.publicPath%>favicon.png" rel="icon">
</head>
<body>
<div id="root"></div>
</body>
</html>
After:
<!DOCTYPE html>
<html>
<head>
<link href="<%=assetPrefix%>/favicon.png" rel="icon">
</head>
<body>
<div id="root"></div>
</body>
</html>
#
Update scripts
#
dev
Update the dev script to run Rsbuild instead of webpack.
Before:
"scripts": {
"dev": "webpack serve --config webpack.dev.js"
}
After:
"scripts": {
"dev": "rsbuild dev --config rsbuild.dev.ts"
}
#
build
Update the build script to run Rsbuild instead of webpack.
Before:
"scripts": {
"build": "webpack --config webpack.build.js"
}
After:
"scripts": {
"build": "rsbuild build --config rsbuild.build.ts"
}
#
Typings
If you're encountering typing issues, consider adding type declarations for the following
#
Storybook
Consider using the new Rsbuild Storybook shared configurations.
#
Try it 🚀
Start the application in a development environment using the dev and build script. Everything should run smoothly without any warnings or errors outputted in the terminal.