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

Open
wants to merge 38 commits into
base: master
Choose a base branch
from
Open

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.69KB -
static/js/cozy.(hash).js
+795.43KB -
public/static/js/cozy.(hash).js
+662.45KB -
(hash).js
+337.62KB -
public/(hash).js
+337.62KB -
services/qualificationMigration.js
+271.92KB -
services/dacc.js
+254.86KB -
static/js/main.(hash).js
+121.48KB -
public/static/js/public.(hash).js
+98.42KB -
public/static/js/lib-react.(hash).js
+39.37KB -
static/js/lib-react.(hash).js
+39.37KB -
static/css/cozy.(hash).css
+32.78KB -
public/static/css/cozy.(hash).css
+32.57KB -
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
-160.87KB -
public/cozy-client-js.js
-159.28KB -
intents/drive.(hash).js
-86.62KB -
public/drive.(hash).min.css
-39.54KB -
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
-507B -
manifest.json
-185B -
Files updated (1)
Status Path Size Limits
index.html
656B (+59B +9.88%) -
Unchanged files (1)
Status Path Size Limits
manifest.webapp
1.91KB -

Total files change -596.49KB -10.09%

Groups added (3)
Status Path Size Limits
**/*.js
+6.84MB -
**/*.{png,svg,ico}
+2.2MB -
**/*.css
+127.39KB -
Groups removed (7)
Status Path Size Limits
public/**
-2.63MB -
vendors/**
-2.32MB -
services/**
-547.14KB -
app/**
-160.87KB -
intents/**
-87.12KB -
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 4 times, most recently from 6975fba to 67e92a4 Compare January 29, 2025 10:01
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

Warning: This would fix the `fil-content-row-selected` class
attribution, however this class is not compatible yet with dark theme,
so we want to enforce `undefined` until we fix the theme. Until then
the behaviour will be like before when the `selected` variable was
always `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
@Ldoppea Ldoppea force-pushed the feat/migrate-to-rsbuild branch from 67e92a4 to 5aeb3c3 Compare January 30, 2025 10:14
package.json Outdated
"watch": "cozy-scripts watch --barV7 false --cozyClientJs",
"start": "cozy-scripts start --barV7 false --cozyClientJs",
"build": "rsbuild build",
"watch": "rsbuild build --watch",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on pourrait garder le start ici non ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pourquoi avoir déplacé les assets statiques dans /public ? Y'a t-il une raison en lien avec rsbuild ?

@@ -24,19 +24,11 @@
name="viewport"
content="width=device-width, height=device-height, initial-scale=1, viewport-fit=cover"
/>
<% if (__STACK_ASSETS__) { %>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

le __STACK_ASSETS__ c'est pas les overrides ? Est-ce qu'on ne perd pas cette feature au passage ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

à quoi ça sert si les alias "directs" (genre modules, components etc.) existent 🤔 Ne faudrait-il pas les supprimer au passage ? Garder les deux approches me semble inutile non ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on avait pas déplacé les assets dans /public justement ? 🤔

const filContentRowSelected = cx(styles['fil-content-row'], {
[styles['fil-content-row-selected']]: selected,
[styles['fil-content-row-selected']]: undefined, // TODO: replace with `selected` and fix dark theme for this variable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

est-ce que le TODO est traité plus tard ?

@@ -9,7 +9,6 @@
"cozyPublish": "cozy-app-publish --token $REGISTRY_TOKEN --prepublish downcloud --postpublish mattermost",
"tx": "tx pull --all || true",
"lint": "npm-run-all --parallel 'lint:*'",
"lint:styles": "stylint src --config ./node_modules/cozy-scripts/config/.stylintrc",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

est-ce qu'on le remet plus tard ?

@@ -5,6 +5,7 @@
"scripts": {
"build": "rsbuild build",
"watch": "rsbuild build --watch --mode development",
"start": "rsbuild dev",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: le commentaire du commit n'est pas raccord avec le code (yarn dev d'un côté, yarn start de l'autre)

@@ -92,6 +92,7 @@
"cozy-flags": "^4.6.1",
"cozy-harvest-lib": "^32.2.6",
"cozy-intent": "^2.29.1",
"cozy-interapp": "^0.15.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pourquoi donc ? C'était une coquille sur Drive ou c'est en lien avec la migration ?

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