<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Saurabh</title>
    <description>The latest articles on Forem by Saurabh (@saurabhkhoshya).</description>
    <link>https://forem.com/saurabhkhoshya</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1505076%2Fd8c2c69d-6dff-4254-a8f0-830abca97305.jpg</url>
      <title>Forem: Saurabh</title>
      <link>https://forem.com/saurabhkhoshya</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/saurabhkhoshya"/>
    <language>en</language>
    <item>
      <title>CRA to Rspack Migration: 5-10x Faster React Builds</title>
      <dc:creator>Saurabh</dc:creator>
      <pubDate>Sun, 26 May 2024 13:43:51 +0000</pubDate>
      <link>https://forem.com/saurabhkhoshya/cra-to-rspack-migration-5-10x-faster-react-builds-5el5</link>
      <guid>https://forem.com/saurabhkhoshya/cra-to-rspack-migration-5-10x-faster-react-builds-5el5</guid>
      <description>&lt;h2&gt;
  
  
  What is &lt;a href="https://create-react-app.dev/"&gt;CRA&lt;/a&gt;?
&lt;/h2&gt;

&lt;p&gt;CRA is a fantastic tool for getting started with React development. Easy to use and well documented and provides a solid foundation for the project. Under the hood it uses webpack, Babel, ESLint, additional Tools and libraries. Developers can more focused on implementing business logic rather than configuring all these setups by own.&lt;/p&gt;

&lt;h2&gt;
  
  
  Need for Rust based bundlers:
&lt;/h2&gt;

&lt;p&gt;The performance of bundling and HRM is directly proportional to the codebase size, for large code-base apps bundling by webpack takes a lot of time.&lt;br&gt;
As your application grows in complexity you might start to notice performance bottlenecks in the build process.&lt;br&gt;
&lt;a href="https://www.rspack.dev/"&gt;Rspack&lt;/a&gt; is a next-generation bundler designed for lightning-fast 5 to 10x faster builds. It built on the high-performance Rust programming language&lt;/p&gt;
&lt;h2&gt;
  
  
  Migration Steps:
&lt;/h2&gt;

&lt;p&gt;Create React App (CRA) itself has many built-in capabilities so manually setting up an equivalent configuration using &lt;code&gt;@rspack/cli&lt;/code&gt; can be challenging.&lt;br&gt;
For migration, we will use &lt;a href="https://rsbuild.dev/"&gt;rsbuild&lt;/a&gt; which is an &lt;a href="https://www.rspack.dev/"&gt;Rspack&lt;/a&gt;-based build tool for the web. The main goal of &lt;a href="https://rsbuild.dev/"&gt;Rsbuild&lt;/a&gt; is to provide out-of-the-box build capabilities for &lt;a href="https://www.rspack.dev/"&gt;Rspack&lt;/a&gt; users, allowing developers to start a web project with zero configuration.&lt;/p&gt;

&lt;p&gt;We have set up a &lt;a href="https://github.com/saurabhkhoshya/migrate-create-react-app-to-rspack"&gt;demo react application generated by CRA&lt;/a&gt;, let migrate it in to &lt;a href="https://www.rspack.dev/"&gt;rspack&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu3hhr6pbjjmol0klapaz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu3hhr6pbjjmol0klapaz.png" alt="Image description" width="800" height="477"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;: &lt;br&gt;
Remove CRA dependencies&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm remove react-scripts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: install &lt;a href="https://rsbuild.dev/[](url)"&gt;Rsbuild&lt;/a&gt; dependencies&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm add @rsbuild/core @rsbuild/plugin-react -D
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Step 3&lt;/strong&gt;: Updating npm scripts in &lt;code&gt;package.json&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "scripts": {
   "start": "react-scripts start",
   "build": "react-scripts build",
   "eject": "react-scripts eject"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Replace with &lt;a href="https://rsbuild.dev/"&gt;Rsbuild's&lt;/a&gt; CLI commands&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "scripts": {
    "start": "rsbuild dev",
    "build": "rsbuild build",
    "preview": "rsbuild preview"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Step 4&lt;/strong&gt;: Creating Configuration File&lt;/p&gt;

&lt;p&gt;Create a &lt;a href="https://rsbuild.dev/"&gt;Rsbuild&lt;/a&gt; configuration file &lt;code&gt;rsbuild.config.ts&lt;/code&gt; in the same directory as &lt;code&gt;package.json&lt;/code&gt; and add the following content:&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { defineConfig } from '@rsbuild/core';
import { pluginReact } from '@rsbuild/plugin-react';

export default defineConfig({
  plugins: [pluginReact()],
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fml0f8ekt1gkhg33ielle.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fml0f8ekt1gkhg33ielle.png" alt="Image description" width="800" height="265"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5&lt;/strong&gt;: Basic migration has done, you can start an application by running &lt;code&gt;npm run start&lt;/code&gt; and for build run &lt;code&gt;npm run build&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Below is the build performance, &lt;em&gt;build time drops from around 11 seconds to 2 sec&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq21hlaichoc4wkuxq83w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq21hlaichoc4wkuxq83w.png" alt="Image description" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the &lt;a href="https://github.com/saurabhkhoshya/migrate-create-react-app-to-rspack"&gt;link for a git repo for the CRA to Rspack Migration&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;For more detailed and advanced config check &lt;a href="https://rsbuild.dev/guide/migration/cra"&gt;Rsbuild&lt;/a&gt;&lt;/p&gt;

</description>
      <category>cra</category>
      <category>rspack</category>
      <category>react</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
