The latest addition to my experimental Svelte Bazel rules is optional opt-in to advanced Closure compiler optimizations in the bundle_prod rule. This means you have a choice between Rollup and the Closure compiler when generating prod bundles using bundle_prod.
If you are new to either Bazel or the Closure compiler, I recommend reading two of my other articles first:
Closure Compiler Opt-In
Opt-in to Closure compiler optimizations in bundle_prod is done by specifying a closure compiler configuration file in the rule definition. I have provided a simple example below.
Omitting the closure_config attribute will fall back to Rollup with Terser instead of the Closure compiler.
In order to tell the Closure compiler how to process the RxJs dependencies we have to specify a little bit of configuration in closure-config.json. In this case we only have to worry about Rxjs, but you could potentially depend on multiple third party libraries in a more realistic application.
RxJs is published in multiple formats, but in this case I am telling the Closure compiler to pick up the esm2015 format.
We also have to give the Closure compiler the entry point of the application code (main.js).
The rest of the Closure compiler configurations are encapsulated by bundle_prod assuming the following settings:
I have uploaded a sample project to Github in case you want to give it a try.
The demo application shows how to use Bazel as the single build tool for building a Go web server that serves a Closure compiled Svelte application.