Introducing a new JS build system for Discourse core

Following successful modernization of the theme and plugin build systems over the last year, we’re now ready to move forward with making a similar upgrade in Discourse core.

Despite being a complete overhaul of the core build system, this change is intended to be fully backwards compatible. Production installations of Discourse shouldn’t notice any changes. The pre-compiled assets system will continue to mean that your servers don’t need to build core assets themselves.

Technologies

We’re moving from ember-cli/webpack to rolldown, a rust-based bundler for JavaScript. Rolldown is the heart of the latest version of Vite, so we’re in good company, and aligned with the direction of the Ember ecosystem.

All of Discourse’s JavaScript is now built to native ES Modules, which brings improved runtime performance, and unlocks a number of future optimisations.

Build Performance

In development, builds should be around 80% faster than before. On my machine[1], that has brought development boot time from ~30s to ~5s. We expect performance to improve further in future, as there are still some parts of the build which lean on older technologies like Babel.

Developer experience

As part of this move, we have decided to stop using a proxy in front of Discourse for development. Development should now be done directly against the Rails server.

bin/ember-cli -u has been replaced with bin/dev. This will launch Rails on :3000, and will run the rolldown build in the background. Log output from both processes will be shown with an appropriate prefix. You should visit :3000 in your browser. :4200 will no longer serve anything.

To help with migration, bin/ember-cli is now a backwards-compatible shim. It will print help information, and will launch a lightweight server on :4200 with instructions to move to :3000.

If you prefer to launch Rails and the JS build as separate commands, you can still do that. Rails boot commands are unchanged, and the rolldown bundler can be run in watch mode using bin/dev --only ember.

Out-of-date build warnings

If the currently-on-disk build was produced using the rolldown development bundler, and that bundler process is no longer running, Rails will throw an error to warn you that assets are out-of-date. This applies to development-mode and system specs.

This error will not be thrown if you use the one-shot build command (pnpm build) like we do in CI.

Thanks!

This work has been made possible by the Ember/Embroider teams, and The Ember Initiative. Particular thanks to @real_ate for his work with us on this project! :tada:


  1. MacBook Pro with M3 Pro chip ↩︎

Wow! That’s awesome! :raising_hands:t3: