Since @rspack/cli
has built-in support for TypeScript, JSX, CSS, etc., it is relatively easy to migrate from the Create React App.
First, we need to update the dependencies, uninstall all the Create React App dependencies, then install the @rspack/cli dependencies and update the corresponding startup scripts.
{
"dependencies": {
- "react-scripts": "5.0.1"
+ "@rspack/cli": "latest"
},
"scripts": {
- "start": "react-scripts start",
- "build": "react-scripts build",
- "test": "react-scripts test"
+ "start": "rspack serve",
+ "build": "rspack build"
}
}
Then, we need to create the rspack.config.js
file in the root of the project to configure rspack-related options. @rspack/cli
does not have all the CRA functionality built-in, so some additional options need to be configured as follows
/** @type {import('@rspack/cli').Configuration} */
const config = {
entry: {
main: './src/index.jsx', // Configure the project entry file
},
builtins: {
html: [
{
template: './index.html', // Align CRA to generate index.html
},
],
copy: {
patterns: [
{
from: 'public',
},
],
},
},
};
module.exports = config;
After ejecting the CRA is also considered a more complex webpack project configuration, the following lists the main things to do when migrating, the detailed code can be referred to rspack-migration-showcase/pull/6。