From b07abaabf6ef1440cd2384f78d3bec4946e76fbf Mon Sep 17 00:00:00 2001 From: Mateusz Starzec Date: Tue, 30 Oct 2018 14:33:22 +0100 Subject: [PATCH 1/6] Publish jQuery wrapper as CommonJS module with global scope fallback --- .travis.yml | 2 +- build.sbt | 52 ++++++++----------- example/README.md | 9 ++++ example/build.sbt | 39 ++++++++++++-- example/project/Dependencies.scala | 2 +- example/project/build.properties | 2 +- example/project/plugins.sbt | 3 +- example/src/main/assets/index-bundler.html | 11 ++++ .../assets/{index.html => index-global.html} | 2 +- project/build.properties | 2 +- project/plugins.sbt | 5 +- .../io/udash/wrappers/jquery/package.scala | 7 ++- .../io/udash/wrappers/jquery/utils.scala | 18 ++++--- 13 files changed, 102 insertions(+), 52 deletions(-) create mode 100644 example/src/main/assets/index-bundler.html rename example/src/main/assets/{index.html => index-global.html} (83%) diff --git a/.travis.yml b/.travis.yml index 92b85a2..6357a9d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,4 +24,4 @@ before_script: script: - sbt ++$TRAVIS_SCALA_VERSION test - sbt ++$TRAVIS_SCALA_VERSION publishLocal - - cd example && sbt ++$TRAVIS_SCALA_VERSION compile fullOptJS \ No newline at end of file + - cd example && sbt ++$TRAVIS_SCALA_VERSION compile jquery-demo/fullOptJS jquery-bundler-demo/compileStatics \ No newline at end of file diff --git a/build.sbt b/build.sbt index 2fbe661..75b940b 100644 --- a/build.sbt +++ b/build.sbt @@ -1,14 +1,12 @@ import org.openqa.selenium.chrome.ChromeOptions -import org.openqa.selenium.remote.DesiredCapabilities -import org.scalajs.jsenv.selenium.SeleniumJSEnv name := "udash-jquery" inThisBuild(Seq( - version := "2.0.1", + version := "3.0.0-SNAPSHOT", organization := "io.udash", - scalaVersion := "2.12.6", - crossScalaVersions := Seq("2.11.12", "2.12.6"), + scalaVersion := "2.12.7", + crossScalaVersions := Seq("2.11.12", "2.12.7"), scalacOptions ++= Seq( "-feature", "-deprecation", @@ -20,35 +18,25 @@ inThisBuild(Seq( "-language:experimental.macros", "-Xfuture", "-Xfatal-warnings", - "-Xlint:_", + "-Xlint:_" ), scalacOptions ++= { - if (CrossVersion.partialVersion((root / scalaVersion).value).contains((2, 12))) Seq( + if (scalaBinaryVersion.value == "2.12") Seq( "-Ywarn-unused:_,-explicits,-implicits", "-Ybackend-parallelism", "4", "-Ycache-plugin-class-loader:last-modified", "-Ycache-macro-class-loader:last-modified" ) else Seq.empty - }, + } )) -// Settings for JS tests run in browser -val browserCapabilities: DesiredCapabilities = { - // requires ChromeDriver: https://sites.google.com/a/chromium.org/chromedriver/ - val capabilities = DesiredCapabilities.chrome() - capabilities.setCapability(ChromeOptions.CAPABILITY, { - val options = new ChromeOptions() - options.addArguments("--headless", "--disable-gpu") - options - }) - capabilities -} - val commonJSSettings = Seq( Compile / emitSourceMaps := true, Test / parallelExecution := false, Test / scalaJSStage := FastOptStage, - Test / jsEnv := new SeleniumJSEnv(browserCapabilities), + // ScalaJSBundlerPlugin does not work with scalajs-env-selenium: + // https://github.com/scalacenter/scalajs-bundler/issues/89 + // Test / jsEnv := new SeleniumJSEnv(browserCapabilities), scalacOptions += { val localDir = (ThisBuild / baseDirectory).value.toURI.toString val githubDir = "https://raw.githubusercontent.com/UdashFramework/scala-js-jquery" @@ -57,15 +45,17 @@ val commonJSSettings = Seq( scalacOptions += "-P:scalajs:sjsDefinedByDefault", ) -libraryDependencies ++= Seq( - "org.scala-js" %%% "scalajs-dom" % "0.9.6", - "org.scalatest" %%% "scalatest" % "3.0.5" % Test, - "com.lihaoyi" %%% "scalatags" % "0.6.7" % Test -) +lazy val root = project.in(file(".")) + .enablePlugins(ScalaJSBundlerPlugin) + .settings( + commonJSSettings, -jsDependencies += - "org.webjars" % "jquery" % "3.3.1" % Test / "3.3.1/jquery.js" minified "3.3.1/jquery.min.js" + libraryDependencies ++= Seq( + "org.scala-js" %%% "scalajs-dom" % "0.9.6", + "org.scalatest" %%% "scalatest" % "3.0.5" % Test, + "com.lihaoyi" %%% "scalatags" % "0.6.7" % Test + ), -lazy val root = project.in(file(".")) - .enablePlugins(ScalaJSPlugin) - .settings(commonJSSettings) + Compile / npmDependencies += "jquery" -> "3.3.1", + Test / requiresDOM := true + ) diff --git a/example/README.md b/example/README.md index bacbfad..94fe2eb 100644 --- a/example/README.md +++ b/example/README.md @@ -1,4 +1,13 @@ +The `build.sbt` file contains two configurations: +* `jquery-demo` uses global jQuery dependency. +* `jquery-bundler-demo` uses `ScalaJSBundlerPlugin` in order to manage module dependencies. + ### How to use? Run `sbt fastOptJS` or `sbt fullOptJS` to compile this demo. You can find all generated files in the `generated` directory. Open `index.html` in your browser. + +### How to use? (ScalaJSBundlerPlugin) + +Run `sbt compileStatics` to compile this demo. You can find all generated files +in the `generated` directory. Open `index.html` in your browser. \ No newline at end of file diff --git a/example/build.sbt b/example/build.sbt index 66c5314..c218e7d 100644 --- a/example/build.sbt +++ b/example/build.sbt @@ -1,10 +1,10 @@ name := "jquery-demo" inThisBuild(Seq( - version := "2.0.0", + version := "3.0.0", organization := "io.udash", - scalaVersion := "2.12.6", - crossScalaVersions := Seq("2.11.12", "2.12.6"), + scalaVersion := "2.12.7", + crossScalaVersions := Seq("2.11.12", "2.12.7"), scalacOptions ++= Seq( "-feature", "-deprecation", @@ -18,7 +18,7 @@ inThisBuild(Seq( "-Xlint:_", ), scalacOptions ++= { - if (CrossVersion.partialVersion((`jquery-demo` / scalaVersion).value).contains((2, 12))) Seq( + if (scalaBinaryVersion.value == "2.12") Seq( "-Ywarn-unused:_,-explicits,-implicits", "-Ybackend-parallelism", "4", "-Ycache-plugin-class-loader:last-modified", @@ -28,6 +28,7 @@ inThisBuild(Seq( )) val generatedDir = file("generated") +val compileStatics = taskKey[Unit]("Compiles all static files.") val copyAssets = taskKey[Unit]("Copies all assets to the target directory.") val `jquery-demo` = project.in(file(".")).enablePlugins(ScalaJSPlugin) .settings( @@ -47,7 +48,7 @@ val `jquery-demo` = project.in(file(".")).enablePlugins(ScalaJSPlugin) copyAssets := { IO.copyFile( - sourceDirectory.value / "main/assets/index.html", + sourceDirectory.value / "main/assets/index-global.html", generatedDir / "index.html" ) }, @@ -60,4 +61,32 @@ val `jquery-demo` = project.in(file(".")).enablePlugins(ScalaJSPlugin) (Compile / packageJSDependencies / crossTarget).value / "scripts" / "frontend-deps.js", Compile / packageMinifiedJSDependencies / artifactPath := (Compile / packageMinifiedJSDependencies / crossTarget).value / "scripts" / "frontend-deps.js" + ) + +val `jquery-bundler-demo` = project.in(file(".")) + .enablePlugins(ScalaJSBundlerPlugin) + .settings( + libraryDependencies ++= Dependencies.deps.value, + + Compile / scalaJSUseMainModuleInitializer := true, + + copyAssets := { + IO.copyFile( + sourceDirectory.value / "main/assets/index-bundler.html", + generatedDir / "index.html" + ) + }, + + compileStatics := { + val sjsFileName = (Compile / fastOptJS).value.data.name.stripSuffix(".js") + IO.copyFile( + (Compile / npmUpdate / crossTarget).value / s"$sjsFileName-bundle.js", + generatedDir / "scripts/frontend.js" + ) + IO.copyFile( + (Compile / npmUpdate / crossTarget).value / s"$sjsFileName-bundle.js.map", + generatedDir / "scripts/frontend.js.map" + ) + }, + compileStatics := compileStatics.dependsOn(Compile / fastOptJS / webpack, copyAssets).value, ) \ No newline at end of file diff --git a/example/project/Dependencies.scala b/example/project/Dependencies.scala index 44cffc7..821aaeb 100644 --- a/example/project/Dependencies.scala +++ b/example/project/Dependencies.scala @@ -4,7 +4,7 @@ import sbt._ object Dependencies { val udashCoreVersion = "0.6.1" - val udashJQueryVersion = "2.0.0" + val udashJQueryVersion = "3.0.0-SNAPSHOT" val deps = Def.setting(Seq[ModuleID]( "io.udash" %%% "udash-core-frontend" % udashCoreVersion, diff --git a/example/project/build.properties b/example/project/build.properties index 84d4f68..e71780d 100644 --- a/example/project/build.properties +++ b/example/project/build.properties @@ -1 +1 @@ -sbt.version = 1.2.0 \ No newline at end of file +sbt.version = 1.2.6 \ No newline at end of file diff --git a/example/project/plugins.sbt b/example/project/plugins.sbt index a6a5fe1..4ff27ce 100644 --- a/example/project/plugins.sbt +++ b/example/project/plugins.sbt @@ -1,3 +1,4 @@ logLevel := Level.Warn -addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.24") \ No newline at end of file +addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.25") +addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.13.1") \ No newline at end of file diff --git a/example/src/main/assets/index-bundler.html b/example/src/main/assets/index-bundler.html new file mode 100644 index 0000000..5f8226d --- /dev/null +++ b/example/src/main/assets/index-bundler.html @@ -0,0 +1,11 @@ + + + + + jquery-demo - ScalaJSBundlerPlugin demo + + + +
+ + \ No newline at end of file diff --git a/example/src/main/assets/index.html b/example/src/main/assets/index-global.html similarity index 83% rename from example/src/main/assets/index.html rename to example/src/main/assets/index-global.html index fd8b57a..13da206 100644 --- a/example/src/main/assets/index.html +++ b/example/src/main/assets/index-global.html @@ -2,7 +2,7 @@ - jquery-demo + jquery-demo - global scope diff --git a/project/build.properties b/project/build.properties index 84d4f68..e71780d 100755 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version = 1.2.0 \ No newline at end of file +sbt.version = 1.2.6 \ No newline at end of file diff --git a/project/plugins.sbt b/project/plugins.sbt index 9ffbb26..7135c5b 100755 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,5 +1,6 @@ logLevel := Level.Warn -libraryDependencies += "org.scala-js" %% "scalajs-env-selenium" % "0.2.0" +libraryDependencies += "org.scala-js" %% "scalajs-env-selenium" % "0.3.0" -addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.24") +addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.25") +addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.13.1") diff --git a/src/main/scala/io/udash/wrappers/jquery/package.scala b/src/main/scala/io/udash/wrappers/jquery/package.scala index 16a83bd..cf43fa1 100644 --- a/src/main/scala/io/udash/wrappers/jquery/package.scala +++ b/src/main/scala/io/udash/wrappers/jquery/package.scala @@ -3,6 +3,7 @@ package io.udash.wrappers import org.scalajs.dom._ import scala.scalajs.js +import scala.scalajs.js.annotation.JSImport /** All docs are quoted from jQuery API docs. */ package object jquery { @@ -12,5 +13,7 @@ package object jquery { type EventName = String type JQueryCallback = (Element, JQueryEvent) => Any - def jQ: JQueryStatic = js.Dynamic.global.jQuery.asInstanceOf[JQueryStatic] -} + @js.native + @JSImport("jquery", JSImport.Default, "$") + object jQ extends JQueryStatic +} \ No newline at end of file diff --git a/src/main/scala/io/udash/wrappers/jquery/utils.scala b/src/main/scala/io/udash/wrappers/jquery/utils.scala index 4c18fdb..ac287b1 100644 --- a/src/main/scala/io/udash/wrappers/jquery/utils.scala +++ b/src/main/scala/io/udash/wrappers/jquery/utils.scala @@ -12,12 +12,18 @@ sealed trait TopLeftCoords { case class Position(override val top: Double, override val left: Double) extends TopLeftCoords case class Offset(override val top: Double, override val left: Double) extends TopLeftCoords -case class AnimationOptions(duration: Option[Int] = None, easing: Option[EasingFunction] = None, queue: Option[Boolean] = None, - step: (Int, js.Dynamic) => Any = null, progress: (JQueryPromise[js.Function1[js.Any, js.Any], js.Any], Int, Int) => Any = null, - complete: () => Any = null, start: JQueryPromise[js.Function1[js.Any, js.Any], js.Any] => Any = null, - done: (JQueryPromise[js.Function1[js.Any, js.Any], js.Any], Boolean) => Any = null, - fail: (JQueryPromise[js.Function1[js.Any, js.Any], js.Any], Boolean) => Any = null, - always: (JQueryPromise[js.Function1[js.Any, js.Any], js.Any], Boolean) => Any = null) { +case class AnimationOptions( + duration: Option[Int] = None, + easing: Option[EasingFunction] = None, + queue: Option[Boolean] = None, + step: (Int, js.Dynamic) => Any = null, + progress: (JQueryPromise[js.Function1[js.Any, js.Any], js.Any], Int, Int) => Any = null, + complete: () => Any = null, + start: JQueryPromise[js.Function1[js.Any, js.Any], js.Any] => Any = null, + done: (JQueryPromise[js.Function1[js.Any, js.Any], js.Any], Boolean) => Any = null, + fail: (JQueryPromise[js.Function1[js.Any, js.Any], js.Any], Boolean) => Any = null, + always: (JQueryPromise[js.Function1[js.Any, js.Any], js.Any], Boolean) => Any = null +) { def toJSDictionary: js.Dictionary[Any] = { val r = js.Dictionary[Any]() if (duration.isDefined) r.update("duration", duration.get) From 64677a4b8a0d5eb330097cace5732f3dc67dd6a9 Mon Sep 17 00:00:00 2001 From: Mateusz Starzec Date: Wed, 31 Oct 2018 08:28:57 +0100 Subject: [PATCH 2/6] Improved jQuery demo build configuration: two modules with shared sources --- .travis.yml | 4 +- example/README.md | 8 +-- example/build.sbt | 56 ++++++++++++++----- .../src/main/assets/index.html} | 0 .../src/main/assets/index.html} | 0 5 files changed, 47 insertions(+), 21 deletions(-) rename example/{src/main/assets/index-bundler.html => bundler-demo/src/main/assets/index.html} (100%) rename example/{src/main/assets/index-global.html => global-demo/src/main/assets/index.html} (100%) diff --git a/.travis.yml b/.travis.yml index 6357a9d..49f4d8e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ dist: trusty jdk: oraclejdk8 scala: - 2.11.12 - - 2.12.6 + - 2.12.7 before_script: - "export DISPLAY=:99.0" @@ -24,4 +24,4 @@ before_script: script: - sbt ++$TRAVIS_SCALA_VERSION test - sbt ++$TRAVIS_SCALA_VERSION publishLocal - - cd example && sbt ++$TRAVIS_SCALA_VERSION compile jquery-demo/fullOptJS jquery-bundler-demo/compileStatics \ No newline at end of file + - cd example && sbt ++$TRAVIS_SCALA_VERSION compile jquery-global-demo/fullOptJS jquery-bundler-demo/compileStatics \ No newline at end of file diff --git a/example/README.md b/example/README.md index 94fe2eb..bcb3feb 100644 --- a/example/README.md +++ b/example/README.md @@ -4,10 +4,10 @@ The `build.sbt` file contains two configurations: ### How to use? -Run `sbt fastOptJS` or `sbt fullOptJS` to compile this demo. You can find all generated files -in the `generated` directory. Open `index.html` in your browser. +Run `sbt jquery-global-demo/fastOptJS` or `sbt jquery-global-demo/fullOptJS` to compile this demo. You can find all generated files +in the `generated/global` directory. Open `index.html` in your browser. ### How to use? (ScalaJSBundlerPlugin) -Run `sbt compileStatics` to compile this demo. You can find all generated files -in the `generated` directory. Open `index.html` in your browser. \ No newline at end of file +Run `sbt jquery-bundler-demo/compileStatics` to compile this demo. You can find all generated files +in the `generated/bundler` directory. Open `index.html` in your browser. \ No newline at end of file diff --git a/example/build.sbt b/example/build.sbt index c218e7d..64f9a69 100644 --- a/example/build.sbt +++ b/example/build.sbt @@ -27,19 +27,20 @@ inThisBuild(Seq( }, )) -val generatedDir = file("generated") -val compileStatics = taskKey[Unit]("Compiles all static files.") +val generatedGlobalDir = file("generated/global") val copyAssets = taskKey[Unit]("Copies all assets to the target directory.") -val `jquery-demo` = project.in(file(".")).enablePlugins(ScalaJSPlugin) +val `jquery-global-demo` = project.in(file("global-demo")).enablePlugins(ScalaJSPlugin) .settings( libraryDependencies ++= Dependencies.deps.value, jsDependencies ++= Dependencies.jsDeps.value, + sourceDirsSettings(_.getParentFile), + /* move these files out of target/. */ - Compile / fullOptJS / crossTarget := generatedDir, - Compile / fastOptJS / crossTarget := generatedDir, - Compile / packageJSDependencies / crossTarget := generatedDir, - Compile / packageMinifiedJSDependencies / crossTarget := generatedDir, + Compile / fullOptJS / crossTarget := generatedGlobalDir, + Compile / fastOptJS / crossTarget := generatedGlobalDir, + Compile / packageJSDependencies / crossTarget := generatedGlobalDir, + Compile / packageMinifiedJSDependencies / crossTarget := generatedGlobalDir, Compile / fastOptJS := (Compile / fastOptJS).dependsOn(copyAssets).value, Compile / fullOptJS := (Compile / fullOptJS).dependsOn(copyAssets).value, @@ -48,8 +49,8 @@ val `jquery-demo` = project.in(file(".")).enablePlugins(ScalaJSPlugin) copyAssets := { IO.copyFile( - sourceDirectory.value / "main/assets/index-global.html", - generatedDir / "index.html" + sourceDirectory.value / "main/assets/index.html", + generatedGlobalDir / "index.html" ) }, @@ -63,17 +64,21 @@ val `jquery-demo` = project.in(file(".")).enablePlugins(ScalaJSPlugin) (Compile / packageMinifiedJSDependencies / crossTarget).value / "scripts" / "frontend-deps.js" ) -val `jquery-bundler-demo` = project.in(file(".")) +val generatedBundlerDir = file("generated/bundler") +val compileStatics = taskKey[Unit]("Compiles all static files.") +val `jquery-bundler-demo` = project.in(file("bundler-demo")) .enablePlugins(ScalaJSBundlerPlugin) .settings( libraryDependencies ++= Dependencies.deps.value, + + sourceDirsSettings(_.getParentFile), Compile / scalaJSUseMainModuleInitializer := true, copyAssets := { IO.copyFile( - sourceDirectory.value / "main/assets/index-bundler.html", - generatedDir / "index.html" + sourceDirectory.value / "main/assets/index.html", + generatedBundlerDir / "index.html" ) }, @@ -81,12 +86,33 @@ val `jquery-bundler-demo` = project.in(file(".")) val sjsFileName = (Compile / fastOptJS).value.data.name.stripSuffix(".js") IO.copyFile( (Compile / npmUpdate / crossTarget).value / s"$sjsFileName-bundle.js", - generatedDir / "scripts/frontend.js" + generatedBundlerDir / "scripts/frontend.js" ) IO.copyFile( (Compile / npmUpdate / crossTarget).value / s"$sjsFileName-bundle.js.map", - generatedDir / "scripts/frontend.js.map" + generatedBundlerDir / "scripts/frontend.js.map" ) }, compileStatics := compileStatics.dependsOn(Compile / fastOptJS / webpack, copyAssets).value, - ) \ No newline at end of file + ) + +def mkSourceDirs(base: File, scalaBinary: String, conf: String): Seq[File] = Seq( + base / "src" / conf / "scala", + base / "src" / conf / s"scala-$scalaBinary", + base / "src" / conf / "java" +) + +def mkResourceDirs(base: File, conf: String): Seq[File] = Seq( + base / "src" / conf / "resources" +) + +def sourceDirsSettings(baseMapper: File => File) = Seq( + Compile / unmanagedSourceDirectories ++= + mkSourceDirs(baseMapper(baseDirectory.value), scalaBinaryVersion.value, "main"), + Compile / unmanagedResourceDirectories ++= + mkResourceDirs(baseMapper(baseDirectory.value), "main"), + Test / unmanagedSourceDirectories ++= + mkSourceDirs(baseMapper(baseDirectory.value), scalaBinaryVersion.value, "test"), + Test / unmanagedResourceDirectories ++= + mkResourceDirs(baseMapper(baseDirectory.value), "test"), +) \ No newline at end of file diff --git a/example/src/main/assets/index-bundler.html b/example/bundler-demo/src/main/assets/index.html similarity index 100% rename from example/src/main/assets/index-bundler.html rename to example/bundler-demo/src/main/assets/index.html diff --git a/example/src/main/assets/index-global.html b/example/global-demo/src/main/assets/index.html similarity index 100% rename from example/src/main/assets/index-global.html rename to example/global-demo/src/main/assets/index.html From f8e3a2454cdf7ba402fde2ebc2b2edbea82444ba Mon Sep 17 00:00:00 2001 From: Mateusz Starzec Date: Wed, 31 Oct 2018 10:09:39 +0100 Subject: [PATCH 3/6] SBT settings cleanup --- build.sbt | 8 ++++++-- example/build.sbt | 17 +++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/build.sbt b/build.sbt index 75b940b..75d1163 100644 --- a/build.sbt +++ b/build.sbt @@ -5,6 +5,9 @@ name := "udash-jquery" inThisBuild(Seq( version := "3.0.0-SNAPSHOT", organization := "io.udash", +)) + +val commonSettings = Seq( scalaVersion := "2.12.7", crossScalaVersions := Seq("2.11.12", "2.12.7"), scalacOptions ++= Seq( @@ -28,13 +31,13 @@ inThisBuild(Seq( "-Ycache-macro-class-loader:last-modified" ) else Seq.empty } -)) +) val commonJSSettings = Seq( Compile / emitSourceMaps := true, Test / parallelExecution := false, Test / scalaJSStage := FastOptStage, - // ScalaJSBundlerPlugin does not work with scalajs-env-selenium: + // ScalaJSBundlerPlugin does not work with scalajs-env-selenium: // https://github.com/scalacenter/scalajs-bundler/issues/89 // Test / jsEnv := new SeleniumJSEnv(browserCapabilities), scalacOptions += { @@ -48,6 +51,7 @@ val commonJSSettings = Seq( lazy val root = project.in(file(".")) .enablePlugins(ScalaJSBundlerPlugin) .settings( + commonSettings, commonJSSettings, libraryDependencies ++= Seq( diff --git a/example/build.sbt b/example/build.sbt index 64f9a69..2a277dc 100644 --- a/example/build.sbt +++ b/example/build.sbt @@ -3,6 +3,9 @@ name := "jquery-demo" inThisBuild(Seq( version := "3.0.0", organization := "io.udash", +)) + +val commonSettings = Seq( scalaVersion := "2.12.7", crossScalaVersions := Seq("2.11.12", "2.12.7"), scalacOptions ++= Seq( @@ -25,13 +28,19 @@ inThisBuild(Seq( "-Ycache-macro-class-loader:last-modified" ) else Seq.empty }, -)) + + libraryDependencies ++= Dependencies.deps.value +) val generatedGlobalDir = file("generated/global") val copyAssets = taskKey[Unit]("Copies all assets to the target directory.") +val root = project.in(file(".")).enablePlugins(ScalaJSPlugin) + .settings(commonSettings) + val `jquery-global-demo` = project.in(file("global-demo")).enablePlugins(ScalaJSPlugin) .settings( - libraryDependencies ++= Dependencies.deps.value, + commonSettings, + jsDependencies ++= Dependencies.jsDeps.value, sourceDirsSettings(_.getParentFile), @@ -69,8 +78,8 @@ val compileStatics = taskKey[Unit]("Compiles all static files.") val `jquery-bundler-demo` = project.in(file("bundler-demo")) .enablePlugins(ScalaJSBundlerPlugin) .settings( - libraryDependencies ++= Dependencies.deps.value, - + commonSettings, + sourceDirsSettings(_.getParentFile), Compile / scalaJSUseMainModuleInitializer := true, From a7ea10c59ae247aaf7086ddfaecfb0b924be9779 Mon Sep 17 00:00:00 2001 From: Mateusz Starzec Date: Wed, 31 Oct 2018 10:09:39 +0100 Subject: [PATCH 4/6] Docs --- README.md | 8 +++++--- example/README.md | 2 +- example/build.sbt | 8 +++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index c62da25..f728a0c 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Static types for the jQuery API for [Scala.js](http://www.scala-js.org/) program Add the following dependency to your SBT build: ```scala -libraryDependencies += "io.udash" %%% "udash-jquery" % "2.0.0" +libraryDependencies += "io.udash" %%% "udash-jquery" % "3.0.0" ``` then import the jQuery package: @@ -16,8 +16,10 @@ then import the jQuery package: import io.udash.wrappers.jquery._ ``` -Since version `2.0.0` the wrapper does not force JS dependency on jQuery. You have to -add it manually by: +Since version `3.0.0` the wrapper is published as a CommonJS module with JS dependencies managed +by [scalajs-bundler](https://github.com/scalacenter/scalajs-bundler). + +If you do not want to use the bundler, you have to include jQuery sources manually by: * explicit link in your `index.html`. ```html
+ + \ No newline at end of file diff --git a/example/global-demo/src/main/assets/index.html b/example/global-demo/src/main/assets/index.html index 13da206..b746eab 100644 --- a/example/global-demo/src/main/assets/index.html +++ b/example/global-demo/src/main/assets/index.html @@ -3,11 +3,11 @@ jquery-demo - global scope - - -
+ + + \ No newline at end of file