armanbilge / scalajs-importmap   0.1.1

Apache License 2.0 GitHub

Use NPM dependencies in Scala.js without a bundler!

Scala versions: 2.13 2.12
sbt plugins: 1.x

scalajs-importmap

An sbt plugin for rewriting @JSImports at linking time in your Scala.js application, à la importmap. This offers an interesting alternative to using bundlers such as Webpack or Vite: instead, you can lean into browsers' native support for ES Modules while loading your dependencies directly from CDNs such as jsdelivr.

Usage

addSbtPlugin("com.armanbilge" % "sbt-scalajs-importmap" % "0.1.0")
enablePlugins(ScalaJSImportMapPlugin)
scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.ESModule))
scalaJSImportMap := { (rawImport: String) =>
  if (rawImport.startsWith("@shoelace-style/shoelace"))
    "https://cdn.jsdelivr.net/npm/" + rawImport
  else
    rawImport
}