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

[VO-1282] chore: Migrate to Rsbuild #3296

Merged
merged 44 commits into from
Feb 11, 2025
Merged

[VO-1282] chore: Migrate to Rsbuild #3296

merged 44 commits into from
Feb 11, 2025

Conversation

Ldoppea
Copy link
Member

@Ldoppea Ldoppea commented Jan 15, 2025

This PR migrate the project's bundler from Webpack to Rsbuild

Non-regression tests have been done:

  • basic app usage
  • reading a PDF file
  • sharing a file
  • invoking the OPEN intent
  • running services using yarn service build/services/<serviceFileName>

Warning

I identified a bug in the File.jsx code where we apply the fil-content-row-selected class on selected files
Previously the variable was always undefined. If I fix this line, I introduce a visual bug on Dark theme, so I chose enforce the undefined until we fix the theme on another PR
See the // TODO comment in the File.jsx file


Performances comparison on my computer:

yarn build

Webpack Rsbuild
Run 1 68,33s 9,00s
Run 2 52,40s 9,59s
Run 3 54,12s 10,72s
Run 4 59,22s 12,40s
Run 5 53,44s 12,44s
Average 57,50s 10,83s

yarn watch

Webpack Rsbuild
Initial build 20,30s 6,64s
Rebuild 1 2,64s 1,42s
Rebuild 2 3,56s 0,73s
Rebuild 3 2,91s 0,72s
Rebuild 4 2,57s 0,77s
Average (initial build removed from average) 2,92s 0,91s

Related PRs:

### 🔧 Tech

* Migrate to Rsbuild

Copy link

bundlemon bot commented Jan 15, 2025

BundleMon

Files added (19)
Status Path Size Limits
static/js/(chunkId).(hash).js
+1.19MB -
public/static/js/(chunkId).(hash).js
+996.75KB -
static/js/cozy.(hash).js
+793.6KB -
public/static/js/cozy.(hash).js
+660.37KB -
(hash).js
+337.62KB -
public/(hash).js
+337.62KB -
services/qualificationMigration.js
+271.92KB -
services/dacc.js
+254.86KB -
static/js/main.(hash).js
+125.62KB -
public/static/js/public.(hash).js
+97.6KB -
public/static/js/lib-react.(hash).js
+39.37KB -
static/js/lib-react.(hash).js
+39.37KB -
static/css/cozy.(hash).css
+32.79KB -
public/static/css/cozy.(hash).css
+32.58KB -
public/static/js/lib-router.(hash).js
+22.05KB -
static/js/lib-router.(hash).js
+22.05KB -
static/css/main.(hash).css
+16.77KB -
public/static/css/public.(hash).css
+6.28KB -
assets/manifest.json
+185B -
Files removed (16)
Status Path Size Limits
vendors/drive.(hash).js
-2.32MB -
public/drive.(hash).js
-2.09MB -
public/pdf.worker.entry.(hash).worker.js
-345.35KB -
services/qualificationMigration/drive.js
-283.77KB -
services/dacc/drive.js
-263.37KB -
app/drive.(hash).js
-161.47KB -
public/cozy-client-js.js
-159.28KB -
intents/drive.(hash).js
-86.75KB -
public/drive.(hash).min.css
-39.55KB -
onlyOffice/slide.pptx
-24.83KB -
app-drive.(hash).min.css
-10.17KB -
intents-drive.(hash).min.css
-8.44KB -
onlyOffice/text.docx
-5.85KB -
onlyOffice/spreadsheet.xlsx
-5.02KB -
intents/index.html
-506B -
manifest.json
-185B -
Files updated (1)
Status Path Size Limits
index.html
684B (+86B +14.38%) -
Unchanged files (1)
Status Path Size Limits
manifest.webapp
1.91KB -

Total files change -599.36KB -10.14%

Groups added (3)
Status Path Size Limits
**/*.js
+6.84MB -
**/*.{png,svg,ico}
+2.19MB -
**/*.css
+127.44KB -
Groups removed (7)
Status Path Size Limits
public/**
-2.63MB -
vendors/**
-2.32MB -
services/**
-547.14KB -
app/**
-161.47KB -
intents/**
-87.25KB -
onlyOffice/**
-35.7KB -
img/**
-5.85KB -

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

@Ldoppea Ldoppea force-pushed the feat/migrate-to-rsbuild branch 2 times, most recently from 98c82cd to 7201534 Compare January 15, 2025 16:52
@zatteo
Copy link
Contributor

zatteo commented Jan 15, 2025

This commit title seems incomplete feat: Migrate index.ejs from

rsbuild.config.mjs Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
@zatteo
Copy link
Contributor

zatteo commented Jan 15, 2025

Great job! 🎉 Can't wait to build faster than light ✨

@zatteo zatteo force-pushed the feat/migrate-to-rsbuild branch 2 times, most recently from cb626f2 to 2f7e44e Compare January 27, 2025 11:03
@Ldoppea Ldoppea force-pushed the feat/migrate-to-rsbuild branch 5 times, most recently from 67e92a4 to 5aeb3c3 Compare January 30, 2025 10:14
package.json Outdated Show resolved Hide resolved
src/targets/vendor/assets/.gitkeep Outdated Show resolved Hide resolved
src/targets/browser/index.ejs Show resolved Hide resolved
src/components/App/App.jsx Outdated Show resolved Hide resolved
manifest.webapp Outdated Show resolved Hide resolved
src/modules/filelist/File.jsx Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
package.json Show resolved Hide resolved
package.json Show resolved Hide resolved
In #3182 we reworked Breadcrumbs to display the root folder and Shared
drives' root as an icon instead of text

Unit tests did not reflect this changes but did continue to pass due to
a bug in cozy-client-js exports making the ROOT_DIR_ID undefined

Since we removed cozy-client-js and used a defined constant instead
then unit tests would fail

This commit fixes all the tests to reflect the new "icon" behavior
Ldoppea and others added 26 commits February 7, 2025 10:16
With the Rsbuild migration, the transpiled code now use `let` and
`const` features contrary to the previous Webpack configuration that
converted them to `var`

This highlight some bug that we previously missed where some variables
were used before being declared. This did not produce any throw when
using `var` due to hoisting, but this may produce bug as the accessed
variable may be undefined
With the Rsbuild migration, the transpiled code now use `let` and
`const` features contrary to the previous Webpack configuration that
converted them to `var`

This highlight some bug that we previously missed where some variables
were used before being declared. This did not produce any throw when
using `var` due to hoisting, but this may produce bug as the accessed
variable may be undefined
In cozy-script we used to enforce the development mode when doing a
`yarn watch`

The development mode changes the build behavior by removing some steps
like minification which results to a faster build

A side effect is that the code generated from the `watch` command is a
bit different than the one generated from `build` command. This may
produce some differences on the app's behavior, but this is rare enough
(happened 1 or 2 times in the past years) so we consider the speed gain
to still be valuable. Also we know that we should run a `build` locally
as ultimate check before pushing new code to the git repo

So we want to enable this mode in the new Rsbuild configuration

Here are the timings for initial build and then 4 differents edits in
the code that trigger a re-build

yarn watch
```
    11,70s (initial build)
    9,87s
    9,89s
    10,10s
    10,80s
```

yarn watch --mode development
```
    6,64s (initial build)
    1,42s
    0,73s
    0,72s
    0,77s
```

Related code:
https://github.com/cozy/create-cozy-app/blob/master/packages/cozy-scripts/scripts/watch.js#L13
`rsbuild-config-cozy-app` has been upgraded to `0.2.0` in order to
retrieve the configuration needed to run `rsbuild dev` with our
cozy-stack based architecture and then benefits from HMR feature

Related PR: cozy/cozy-libs#2700
Since previous commit we can run `rsbuild dev` to enable HMR feature

We now have 3 different scripts:
- `yarn build`: build the app for production
- `yarn watch`: like for the `build` script but with some optimizations
  in order to build faster and to trigger rebuild automatically when
  the code changes
- `yarn dev`: build the app with HMR enabled. This should be the
  fastest way to debug the app, but the HMR feature may prevent the app
  to work in some environments (i.e. flagship app)
`cozy-dataproxy-lib` has been upgraded to `2.3.1` in order to retrieve
a fix on package.json configuration that did not export the dataproxy's
`stylesheet.css`

Related PR: cozy/cozy-libs#2699
By migrating from webpack to rsbuild we lost this resolution override
that is needed by react-pdf for generating PDFs previews using
WebWorkers

More details:
https://github.com/cozy/cozy-libs/blob/a00baa1723bd7d37591fe95dcc1921d4e2c24f87/packages/cozy-viewer/src/Readme.md?plain=1#L299-L335
In previous commit we removed cozy-client-js so we now want Intents to
work with cozy-client instead
This intent seems to be unused anymore as no call can be found in our
entire code base
Since the react-pdf's webpack resolver is declared in
`rsbuild.config.mjs` then we don't need to manually enforce a worker in
PublicViewer

A worker will be used anyway thanks to the webpack resolver
`rsbuild-config-cozy-app` has been upgraded to `0.2.1` in order to
retrieve the configuration needed to run intents and public targets in
the `rsbuild dev` mode

Related PR: cozy/cozy-libs#2717
SVG are loaded differently with rsbuild. It allows the SVG to be correctly centered.
@zatteo zatteo force-pushed the feat/migrate-to-rsbuild branch from 5aeb3c3 to 446b380 Compare February 7, 2025 12:54
`rsbuild-config-cozy-app` has been upgraded to `0.3.0` in order to
retrieve the configuration needed to import images and static assets

Related PR: [cozy/cozy-libs#2728](cozy/cozy-libs#2728)
@zatteo zatteo merged commit 2fb89ec into master Feb 11, 2025
4 checks passed
@zatteo zatteo deleted the feat/migrate-to-rsbuild branch February 11, 2025 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants