Open ebruchez opened 5 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?
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.
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:
window.ORBEON
hierarchyTo clarify the process, here is how things work:
foo-fastopt.js
or foo-opt.js
as usualrequire
, as in:
var $i_ladda = require("ladda");
scalajs-bundler
when using the Application
mode:
npmDependencies
in build.sbt
package.json
node_modules
I think (package.json
as input)
foo-fastopt.js
with the dependencies and resolve module imports and and exportsfoo-fastopt-bundle.js
jsDependencies
should not be used/won't do anything useful.The resulting bundle appears minified by default, including the npmDependencies
modules.
More questions/tasks:
underscore.js
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:
BundlingMode.LibraryAndApplication()
temporarily, while we can still use @JSExportTopLevel
and namespaces (before Scala.js 1.0.0), and see if this works with namespaces-bundle.js
file
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