A very simple plugin that bundles your generated ScalaJS code with its JavaScript dependencies and the JavaScript dependencies of its dependencies.
Uses sbt-npm-dependencies to gather the list of the dependencies, installs them with npm, yarn or bun and them bundles everything with esbuild.
Add this to your project/plugins.sbt
:
addSbtPlugin("com.fiatjaf" %% "sbt-esbuild" % "0.1.1")
In your code, when writing facades, use @JSImport
to refer to the JavaScript modules you're importing (they will get translated to require()
or import
calls and later transpiled by esbuild
).
In your build.sbt, enable the plugin and include your dependencies:
-enablePlugins(ScalaJSPlugin)
+enablePlugins(ScalaJSPlugin, EsbuildPlugin)
+Compile / npmDependencies ++= Seq(
+ "left-pad" -> "latest",
+ "garbage" -> "0.0.0"
+)
+
+esPackageManager = Yarn
If you are importing another Scala library that has declared npmDependencies
using sbt-npm-dependencies (for example, scoin) these dependencies will all be fetched automatically and the @JSImport
annotations from that library will all work.
On sbt
, call fastLinkJS / esBuild
to install dependencies, build and bundle. Or ~fastLinkJS / esBuild
to build continuously. The resulting JS bundle will be written to target/esbuild/bundle.js
(same with fullLinkJS
).
You can also:
- set
esPackageManager
toNpm
,Yarn
orBun
for what to use when installing dependencies (defaults toNpm
); - call
esInstall
to just install the JS modules; or - set
esBuildOptions
(defaults toSeq("--sourcemap")
) to pass extra options to esbuild (it is great since most things work either out-of-the-box or as command-line arguments with no need for bloated configuration files).