eclipse-theia / theia

Eclipse Theia is a cloud & desktop IDE framework implemented in TypeScript.
http://theia-ide.org
Eclipse Public License 2.0
20.05k stars 2.5k forks source link

Build Theia as ESM modules #13272

Open tsmaeder opened 9 months ago

tsmaeder commented 9 months ago

Feature Description:

Currently, Theia is published to npm as a bunch of CommonJS modules. This works fine, but might start to have disadvantages in the future:

  1. We use the ESM build of VS Code for the monaco editor, but consume it as CJS modules: forcing the module type to ESM breaks our uses of vscode stuff in our tests. Since we currently use Webpack for the back end also, the productive build seems to work. However, we need to patch some files in the ESM VS Code build that use the export keyword to use the CJS export convention
  2. More and more published modules switch to ESM-only format: in order to use such modules from CJS modules, we'd have to use the async require function. Webpack can alleviate this problem, unless the modules use "top level async" functionality.
  3. We can't properly tree-shake CJS modules. We could probably expect our artifacts to be around 30% smaller if we could. With our front end artifacts clocking in at around 10mb, using optimized ESM modules might make startup quite a bit faster on slowish connections.
tsmaeder commented 9 months ago

@sdirix, @msujew , @JonasHelming and @tsmaeder had a discussion about this and here's a couple of results:

Overall, we decided moving to ESM is a mid-term project that needs more consideration before implementation.

msujew commented 4 weeks ago

@tsmaeder Now that VS Code's source code is almost completely ESM (see https://github.com/microsoft/vscode/issues/226260), has anything on that last post changed? Can we still consume everything as is?

tsmaeder commented 4 weeks ago

I've prototyped consuming the esm build of VS Code and that seems to work with a couple of webpack magic. As for points 1 and 2 above, I don't think anything has changed.