Skip to content

front: use tsdown instead of rollup - #18201

Open
Signez wants to merge 5 commits into
devfrom
stan/use-tsdown-instead-of-rollup
Open

front: use tsdown instead of rollup#18201
Signez wants to merge 5 commits into
devfrom
stan/use-tsdown-instead-of-rollup

Conversation

@Signez

@Signez Signez commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Did you remember #15693? Yeah, maybe it's time we switch from rollup to the more modern tsdown!

We can't use rolldown directly because it doesn't support CSS bundling at all. It's not a bad thing though, because it pushed me to investigate what is the state of the art in library bundling, and it happens to be tsdown, that we could describe as "vite, but for libraries".

It works well: running npm run build-ui time goes down from 7.7s to 4.9s on my machine, and it also offer the cool feature of actually forwarding Ctrl+click declarations between dependencies (through the usage of the dts.sourcemap feature). And it also properly cleans up the dist folder, so we don't have stale files problems.

Note that I didn't keep the "base" config, as I think the new config files are simple enough it doesn't provide that much of an upside to keep this indirection, in my humble opinion.

@Signez
Signez requested a review from emersion August 19, 2026 15:28
@Signez Signez self-assigned this Aug 19, 2026
@Signez
Signez requested a review from a team as a code owner August 19, 2026 15:28
@Signez Signez moved this to Awaiting merge in Board PI 21 Aug 19, 2026
@github-actions github-actions Bot added the area:front Work on Standard OSRD Interface modules label Aug 19, 2026

@emersion emersion left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

running npm run build-ui time goes down from 7.7s to 4.9s on my machine

I'm relatively unimpressed with this speedup. I was hoping for sub-second build times, to be honest.

Comment thread front/ui/base/package.json
Comment thread front/ui/ui-charts/package.json Outdated
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"main": "dist/index.esm.js",
"main": "dist/index.mjs",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since we have "type": "module", why do we end up with the .mjs file extension?

See https://tsdown.dev/guide/how-it-works#smart-defaults

In general, exposing a .mjs file to outside users can be a pain because these aren't served with the text/javascript MIME type by Web servers.

@Signez Signez Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed; it's because I did not specify that we were building a browser library (through the platform config), so the fixedExtension is true, so the smart default wasn't used. I'll change that.

Edit: It's done ✅

transformer: 'postcss',
},
deps: {
neverBundle: (id, parent, isResolved) => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we really need this? Can't we set neverBundle: true?

See https://tsdown.dev/options/dependencies#externalizing-all-dependencies

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I prefered to err on the side of "not changing the behavior we had before", and this neverBundle function is very basically a port of what we had in the external configuration in rollup-base.

Comment thread front/.oxlintrc.json Outdated
"**/dist/**",
"**/storybook-static/**"
"**/storybook-static/**",
"**/tsdown.config.*"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why ignore tsdown config files here?

@Signez Signez Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It was a way for me to get rid of some irrelevant warnings around the fact that they are the only files that run in a node environment (i.e. without the node types) so Typescript fired some errors.

In the mean time, I found a way to correctly wire Typescript so it doesn't complain anymore (with a tsconfig.node.json and a references: line on each tsconfig.json file), so let's do that instead.

Edit: It's done ✅

@Signez

Signez commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

I'm relatively unimpressed with this speedup. I was hoping for sub-second build times, to be honest.

I agree, but I am convinced further improvement can be made my actually chaining those builds!

(Edit: after discussing it with you IRL, we'll also have to check the workspace support using -W.)

@Signez
Signez force-pushed the stan/use-tsdown-instead-of-rollup branch from 12ef96a to 6fcaa4c Compare August 24, 2026 13:01
@Signez
Signez requested a review from a team as a code owner August 24, 2026 13:03
@github-actions github-actions Bot added the area:ci Work on Continous Integration Pipeline Service label Aug 24, 2026
@Signez

Signez commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

Rebased on dev, all your concerns should be fixed (beside neverBundle).

I also updated npm run build-ui so it calls tsdown directly using the --workspace flag. This lower the time it takes to 4 seconds on my machine; we could get more saving later when we will switch to Typescript 7 to emit types (which is still the slowest part of the pipeline).

@gaetan-osrd gaetan-osrd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM for the dependabot changes

@Signez
Signez requested a review from emersion August 31, 2026 13:06
@Signez
Signez force-pushed the stan/use-tsdown-instead-of-rollup branch 2 times, most recently from 32698c2 to 44f579e Compare September 2, 2026 12:25
@Signez
Signez force-pushed the stan/use-tsdown-instead-of-rollup branch 3 times, most recently from ac92550 to 634fa4b Compare September 7, 2026 12:49
tsdown is somehow a little bit more strict around the usage of the "type" keyword on exports.

Signed-off-by: Stanislas Signoud (Signez) <signez@stanisoft.net>
To do so, we simply have to be explicit on inline paths; using relative, we make them relative to the main.css file (not the one where we use "inline").

Signed-off-by: Stanislas Signoud (Signez) <signez@stanisoft.net>
Most of the changes in the new svgToReact.ts file is a translation to a Typescript file (with a few types added there and there) and wrapping everything into a function.

Signed-off-by: Stanislas Signoud (Signez) <signez@stanisoft.net>
Signed-off-by: Stanislas Signoud (Signez) <signez@stanisoft.net>
@Signez
Signez force-pushed the stan/use-tsdown-instead-of-rollup branch from 634fa4b to 4d232ef Compare September 7, 2026 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ci Work on Continous Integration Pipeline Service area:front Work on Standard OSRD Interface modules area:ui Work on UI kind:technical-enhancement

Projects

Status: Awaiting merge

Development

Successfully merging this pull request may close these issues.

3 participants