orbeon / orbeon-forms

Orbeon Forms is an open source web forms solution. It includes an XForms engine, the Form Builder web-based form editor, and the Form Runner runtime.
http://www.orbeon.com/
GNU Lesser General Public License v2.1
514 stars 221 forks source link

Use webpack/scalajs-bundler to minify files #3897

Open ebruchez opened 5 years ago

ebruchez commented 5 years ago

sbt-web is dead and the UglifyJs we use is fairly broken in that it regularly recompresses all the files.

Seems that we "want to use webpack’s uglify plugin, not sbt’s one", see:

https://github.com/scalacenter/scalajs-bundler/blob/master/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/sharedconfig/prod.webpack.config.js

ebruchez commented 4 years ago

scalajs-bundler allows us to specify npmDependencies in sbt. What's unclear for now is what happens to those: are they just stored into *-fastopt-bundle.js? Are there options?

We have a JavaScript baseline. How would bundling impact that since it's done at compile-time?

ebruchez commented 4 years ago

It seems that webpack can output separate files.

If we use webpack to do the processing (minification, less-to-css, etc.) and still produce individual files/modules, then we can probably keep our baseline/other scheme.

But should we want to use webpack to actually resolve and bundle modules, we might have to revise our dynamic baseline/other scheme.

ebruchez commented 4 years ago

I looked again into scalajs-bundler. It seems that if we want to keep the ability to export things globally, we need:

webpackBundlingMode := BundlingMode.LibraryAndApplication()

But even so, we will no longer be able to use @JSExportTopLevel and namespaces, see this.

So we have to see how we can export our public APIs in a backward-compatible way. We also have some of those APIs which we use internally, for example from xforms.js.

This said I tried enabling scalajs-bundler on formRunnerJS, and I managed to create a bundle and use a dependency with @JSImport (for Ladda) and get things to work.

Next steps:

ebruchez commented 4 years ago

To clarify the process, here is how things work:

The resulting bundle appears minified by default, including the npmDependencies modules.

More questions/tasks:

ebruchez commented 4 years ago

Also, can we make some baby steps in the right direction?

Following the Ladda button experiment, can we handle this with webpack and add to that later? The P1 issues for this are:

ebruchez commented 1 year ago

+1 from customer