Minifying Theia build

Hi! Is there any way to minify Theia build down to a few JS bundles, so I can deliver builds more easily?

[original thread by ivan770]

Did you try running theia build --mode production yet?

[ivan770]

Yep. But still, I’m required to package node_modules when sharing my build. I’m looking for a solution, where webpack builds backend part into bundles too

Right now not, we were looking into but because of time constraints were not able to finish. @kittaakos maybe remember what was particular issues.

Also you cannot webpack everything language servers and so on has to be distributed separately. I think it was the issue actually, look up to 3rd party code was done relative, so if you bundle it cannot be resolved, since bundle.js belongs to another location.

Hi. Even if it’s not possible to minify or bundle the backend, are all the source files, and modules installed during the build, fully required for running the backend in production?

Re modules: for example, puppeteer is ~353Mb. Is it genuinely needed for running the backend? (yarn start doesn’t like it if I delete this; but node src-gen/backend/main.js does launch).

Re files: are all *.ts, *.ts.map, *.tsx, *.js.map files needed? Can any of these be safely deleted?

Please see https://github.com/theia-ide/theia-apps/blob/master/theia-docker/Dockerfile to learn how to create the minimal build. Theia repo is not designed to be the final product, but to develop and publish core extensions.

Thank you!

The yarn --production reduces my build from ~823Mb to ~270Mb.
The yarn autoclean reduces my build to ~214Mb.

Adding *.tsx files to .yarnclean reduces build to ~213Mb.
Adding *.js.map to .yarnclean reduces build to ~181Mb.

Additionally, running find lib -name '*.js.map' -delete reduces my build to 162Mb (since yarn autoclean doesn’t touch the lib directory).

P.S. I trust the *.tsx and *.js.map files are not needed!

1 Like

Thanks for summing it up, @sb

Besides the things you have done, I usually run depcheck and wipe all unused @theia dependencies too.

For example, when I bundle up an electron application, I usually just wipe @theia/monaco or @theia/outline dependencies from the node_modules folder as they are not needed. Why: because neither monaco nor outline have backend contributions, and the frontend part is already in the bundle.js.

1 Like