Vertispan / j2clmavenplugin

Maven plugin to launch new J2CL compilation
https://vertispan.github.io/j2clmavenplugin/
Apache License 2.0
53 stars 26 forks source link

How to import ES6 modules #202

Open appsofteng opened 1 year ago

appsofteng commented 1 year ago

How to use external ES6 modules with j2cl. In particular I tried Firebase web SDK version 9 which is written in TS and compiled into JS. It has multiple modules and some of them import another modules. I tried to compile them with closure but I didn't succeed. The modules have either full http url or npm folder paths in the imports.

The externs work. The only problem is that I need to insert the Firebase imports later when the final closure resulting JS file is generated. I tried to put the imports inside the externs JS file or the native.js file but it causes an error.

Therefore I use maven ant plugin to concat an external file containing import declaration with the final JS file. This solution works but does not go well with the j2cl plugin watch goal.

One solution could be to have a configuration of the j2cl maven plugin that would take a path to an external file with import declarations and insert the contents of the file at the beginning of the resulting JS after the compilation is done.