Giter Site home page Giter Site logo

scalajs-bundler's Introduction

scalajs-bundler Gitter CI

Module bundler for Scala.js projects that use NPM packages.

Uses npm and webpack under the hood.

Documentation

More information on how to use it in the documentation.

Contributing

scalajs-bundler is community-maintained.

Contributions are welcome! See the open issues and the CONTRIBUTING.md file.

License

This content is released under the BSD 3-Clause License.

scalajs-bundler's People

Contributors

ant8e avatar atry avatar cquiroz avatar cranst0n avatar dependabot[bot] avatar dispalt avatar easel avatar fdietze avatar ioleo avatar jtvoorde avatar julienrf avatar kovstas avatar masseguillaume avatar mathieuleclaire avatar mn98 avatar ngbinh avatar nigredo-tori avatar nstojiljkovic avatar ptrdom avatar puneetpatwari avatar raquo avatar scala-center-steward[bot] avatar scala-steward avatar sebruck avatar sjrd avatar swhgoon avatar unarist avatar vhiairrassary avatar vmunier avatar xuwei-k avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

scalajs-bundler's Issues

__webpack_require__ cannot read property

Hi,
I tried scalajs-bundler to package my project scaladget. Scladget exposes several facades for js libs (one of them is a DSL on top of bootstrap.native). In my build.sbt, I construct the scaladget lib and I build another project demo to run some demos of the lib. I'd like to make my scaladget lib depends on the bootstrap.native npm and then make my demo depends on my scaladget lib. I get the following build. The runDemo key constructs the fullOptJS, set the js target in a demo.js file and the webpack target is stored in a scaladget.js file.

lazy val scaladget = project.in(file("scaladget")) settings(
  libraryDependencies += "org.scala-js" %%% "scalajs-dom" % scalaJSdomVersion,
  libraryDependencies += "com.lihaoyi" %%% "scalatags" % scalatagsVersion,
  libraryDependencies += "com.lihaoyi" %%% "scalarx" % rxVersion,
  npmDependencies in Compile += "bootstrap.native" -> bootstrapNativeVersion
  ) enablePlugins(ScalaJSBundlerPlugin, ScalaJSWeb) settings (defaultSettings: _*)


lazy val runDemo = taskKey[Unit]("runDemo")

lazy val demo = project.in(file("demo")) dependsOn (scaladget) enablePlugins(ScalaJSBundlerPlugin, WebScalaJSBundlerPlugin) settings (defaultSettings: _*) settings(
  libraryDependencies += "com.lihaoyi" %%% "scalarx" % rxVersion,
  libraryDependencies += "com.lihaoyi" %%% "sourcecode" % sourceCodeVersion,
  libraryDependencies += "org.scala-lang" % "scala-reflect" % ScalaVersion % "provided",
  scalaJSModuleKind := NoModule,
  runDemo := {
    val demoTarget = target.value
    val demoResource = (resourceDirectory in Compile).value
    IO.copyFile((fullOptJS in Compile).value.data, demoTarget / "js/demo.js")
    (webpack in fullOptJS in Compile).value.foreach { f =>
      IO.copyFile(f, demoTarget / "js/scaladget.js")
    }
    IO.copyFile(demoResource / "index.html", demoTarget / "index.html")
    IO.copyDirectory(demoResource / "js", demoTarget / "js")
    IO.copyDirectory(demoResource / "css", demoTarget / "css")
    IO.copyDirectory(demoResource / "fonts", demoTarget / "fonts")
  )

Then both js are called from my index.html: demo.js from the header and scalaget.js as the final instruction of the Boostrap.main() method (it is a requirement of bootstrap.native).

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min-3.3.7.css">
    <link rel="stylesheet" type="text/css" href="css/style.css">
    <link rel="stylesheet" type="text/css" href="css/github-gist.css">
    <script type="text/javascript" src="js/demo.js"></script>
    <script src="js/highlight.pack.js"></script>
</head>
<body onload="demo.BootstrapDemo().main();"></body>
</html>

When calling the demo.BoostrapDemo().main() method, the following error occurs:

scaladget.js:47Uncaught TypeError: Cannot read property 'BootstrapDemo' of undefined(anonymous function)

refering to the scaladget.js file (47):

__webpack_require__(1)["demo"]["BootstrapDemo"]().main()

The scaladget.js file is attached as a txt file: scaladget.txt

I guess I missed something but I do not understand what. Do I use the scalajs-bundler plugins properly ?
Thanks for helping and congrats for this developpement !

Mathieu

sbt-scalajs-bundler/scripted sbt-scalajs-bundler/facade fails

Tested on windows with command sbt "sbt-scalajs-bundler/scripted sbt-scalajs-bundler/facade"

Error and trace:

[info] [error] C:\Users\Dylan\AppData\Local\Temp\sbt_ff8ea89d\facade\usage\src\main\scala\example\Foo.scala:3: object uuid is not a member of package uuid
[info] [error] import uuid.uuid
[info] [error]        ^
[info] [error] C:\Users\Dylan\AppData\Local\Temp\sbt_ff8ea89d\facade\usage\src\main\scala\example\Foo.scala:7: object v4 is not a member of package uuid
[info] [error]   def bar(): String = uuid.v4()
[info] [error]                            ^
[info] [error] two errors found
[info] [error] (usage/compile:compileIncremental) Compilation failed
[info] [error] Total time: 6 s, completed Nov 3, 2016 11:14:03 PM
[error] x sbt-scalajs-bundler / facade
[error]    {line 1}  Command failed: usage/run failed
java.lang.RuntimeException: Failed tests:
        sbt-scalajs-bundler / facade

        at scala.sys.package$.error(package.scala:27)
        at sbt.test.ScriptedRunner.runAll(ScriptedTests.scala:156)
        at sbt.test.ScriptedRunner.run(ScriptedTests.scala:151)
        at sbt.test.ScriptedRunner.run(ScriptedTests.scala:125)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at sbt.ScriptedPlugin$$anonfun$scriptedTask$1$$anonfun$apply$3$$anonfun$apply$4.apply(ScriptedPlugin.scala:61)
        at sbt.ScriptedPlugin$$anonfun$scriptedTask$1$$anonfun$apply$3$$anonfun$apply$4.apply(ScriptedPlugin.scala:57)
        at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
        at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
        at sbt.std.Transform$$anon$4.work(System.scala:63)
        at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
        at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
        at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
        at sbt.Execute.work(Execute.scala:237)
        at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
        at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
        at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
        at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
[error] (sbt-scalajs-bundler/*:scripted) Failed tests:
[error]         sbt-scalajs-bundler / facade

Improve caching behavior for tasks

webpack task

Current implementation of the webpack task only actually launches webpack if one the following changes:

  1. Generated configuration files (package.json, scalajs.webpack.config.js).
  2. Custom webpack configuration file (if any).
  3. Entries generated by scalajs.

This is a major inconvenience in the following use cases:

  1. If the custom config imports another file (for example if few configs reuse some base settings), webpack won't be launched if only the imported file has changed.
  2. If the code imports some unmanaged resource (script or something else), webpack won't be launched.

There is currently no satisfactory way to circumvent this behavior. Here are a few ideas:

  1. Expose a setting to allow appending to the list of files being checked.
  2. Expose the same functionality without caching as a separate task.
  3. Just disable caching for this task.

package.json generation

Current implementation only regenerates package.json if running with changed sbt Configuration (Compile, Test, etc.). This means that changing npmDependencies/npmDevDependencies won't trigger package.json update.

Possible solutions:

  1. Append these settings to the hash in PackageJsonTasks.scala.
  2. Hash the generated data instead of just using configuration name.

bundling for nodejs

Hi there,

I tried bundling for nodejs by creating a custom webpack config:

var webpack = require('webpack');

module.exports = require('./scalajs.webpack.config');

// make sure all deps are for nodejs
module.exports.target = "node";

What I noticed is that

  • The custom webpack config is not being used unless I set
    enableReloadWorkflow := false
  • Furthermore, I get many warnings when running the webpack task. Here is an example:
[info] WARNING in ./app-backend-fastopt.js
[info] Cannot find source file 'https://raw.githubusercontent.com/scala-js/scala-js/v0.6.13/tools/scalajsenv.js': Error: Cannot resolve 'file' or 'directory' ./https://raw.githubusercontent.com/scala-js/scala-js/v0.6.13/tools/s
calajsenv.js in /home/thomas/data/gitspace/scalajs-webapp/app-backend/target/scala-2.11

Any idea on how to fix this?

I've created a github repo, so you can reproduce the problem:
https://github.com/MHOOO/scalajs-nodejs-react-template

Use distinct working directories for fastOptJS, fullOptJS, npmUpdate and webpack

Currently, everything is put in crossTarget in stage (where stage is either fastOptJS or fullOptJS). In practice this directory is always target/scala-2.11/. It might be better to use distinct npm working directories for the fastOptJS, fullOptJS and the various usages of the npm command, so that the build is more predictable, and we can improve caching.

Duplicate dependencies in package.json when a project depends on several sub-projects

Example of generated package.json file for scalajs-react:

{
  "dependencies": {
    "react-dom": "15.3.2",
    "sizzle": "2.3.0",
    "react-addons-test-utils": "15.3.2",
    "react-dom": "15.3.2",
    "sizzle": "2.3.0",
    "react-addons-test-utils": "15.3.2",
    "react": "15.3.2",
    "react-dom": "15.3.2",
    "react-addons-perf": "15.3.2",
    "react-addons-css-transition-group": "15.3.2"
  },
  "devDependencies": {
    "webpack": "1.13",
    "concat-with-sourcemaps": "1.0.4",
    "source-map-loader": "0.1.5"
  }
}

We should group dependencies by name and check that for each one there is no more than one version (in such a case, we should emit a warning and arbitrarily select the first one).

Linker used concurrently

I periodically get the following exception, when issuing the fastOptJS::webpack command, but never after a fresh clean.

fastOptJS::webpack
[info] Fast optimizing /home/thomas/data/gitspace/scalajs-webapp/app-backend/public/javascripts/frontend-fastopt.js
[trace] Stack trace suppressed: run last frontend/compile:fastOptJS for the full output.
[error] (frontend/compile:fastOptJS) java.lang.IllegalStateException: Linker used concurrently
[error] Total time: 4 s, completed Dec 14, 2016 10:11:17 AM
> last frontend/compile:fastOptJS
[info] Fast optimizing /home/thomas/data/gitspace/scalajs-webapp/app-backend/public/javascripts/frontend-fastopt.js
java.lang.IllegalStateException: Linker used concurrently
        at org.scalajs.core.tools.linker.Linker.guard(Linker.scala:58)
        at org.scalajs.core.tools.linker.Linker.link(Linker.scala:49)
        at org.scalajs.core.tools.linker.ClearableLinker$$anonfun$link$1.apply(ClearableLinker.scala:51)
        at org.scalajs.core.tools.linker.ClearableLinker$$anonfun$link$1.apply(ClearableLinker.scala:51)
        at org.scalajs.core.tools.linker.ClearableLinker.linkerOp(ClearableLinker.scala:62)
        at org.scalajs.core.tools.linker.ClearableLinker.link(ClearableLinker.scala:51)
        at org.scalajs.sbtplugin.ScalaJSPluginInternal$$anonfun$org$scalajs$sbtplugin$ScalaJSPluginInternal$$scalaJSStageSettings$4$$anonfun$apply$6$$anonfun$apply$7.apply(ScalaJSPluginInternal.scala:251)
        at org.scalajs.sbtplugin.ScalaJSPluginInternal$$anonfun$org$scalajs$sbtplugin$ScalaJSPluginInternal$$scalaJSStageSettings$4$$anonfun$apply$6$$anonfun$apply$7.apply(ScalaJSPluginInternal.scala:239)
        at sbt.FileFunction$$anonfun$cached$1.apply(Tracked.scala:253)
        at sbt.FileFunction$$anonfun$cached$1.apply(Tracked.scala:253)
        at sbt.FileFunction$$anonfun$cached$2$$anonfun$apply$3$$anonfun$apply$4.apply(Tracked.scala:267)
        at sbt.FileFunction$$anonfun$cached$2$$anonfun$apply$3$$anonfun$apply$4.apply(Tracked.scala:263)
        at sbt.Difference.apply(Tracked.scala:224)
        at sbt.Difference.apply(Tracked.scala:206)
        at sbt.FileFunction$$anonfun$cached$2$$anonfun$apply$3.apply(Tracked.scala:263)
        at sbt.FileFunction$$anonfun$cached$2$$anonfun$apply$3.apply(Tracked.scala:262)
        at sbt.Difference.apply(Tracked.scala:224)
        at sbt.Difference.apply(Tracked.scala:200)
        at sbt.FileFunction$$anonfun$cached$2.apply(Tracked.scala:262)
        at sbt.FileFunction$$anonfun$cached$2.apply(Tracked.scala:260)
        at org.scalajs.sbtplugin.ScalaJSPluginInternal$$anonfun$org$scalajs$sbtplugin$ScalaJSPluginInternal$$scalaJSStageSettings$4$$anonfun$apply$6.apply(ScalaJSPluginInternal.scala:256)
        at org.scalajs.sbtplugin.ScalaJSPluginInternal$$anonfun$org$scalajs$sbtplugin$ScalaJSPluginInternal$$scalaJSStageSettings$4$$anonfun$apply$6.apply(ScalaJSPluginInternal.scala:237)
        at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
        at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
        at sbt.std.Transform$$anon$4.work(System.scala:63)
        at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
        at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
        at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
        at sbt.Execute.work(Execute.scala:237)
        at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
        at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
        at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
        at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
[error] (frontend/compile:fastOptJS) java.lang.IllegalStateException: Linker used concurrently
>

This happens on my slower netbook, but never on my faster desktop machine. Not sure how to go about debugging this. Any pointers?

Relax NPM dependency version conflict resolution

Current implementation requires that for each NPM package all version descriptors match exactly (for example, 15.4.2 and ~15.4.2 don't match). So any such "conflict" must be resolved explicitly via npmResolutions. This is not a big problem at the moment, but is likely to become more of an issue as the number of libraries using the bundler grows.
There are two ways to deal with this I can think of:

  1. Automatic resolution for such conflicts within the plugin itself. This would, however, require adding and maintaining conflict resolution code compatible with package.json specification.
  2. A much simpler solution would be to delegate such resolution to npm/yarn themselves. package.json supports passing multiple version descriptors, which should be perfect for this purpose.

sbt-web-scalajs-bundler/scripted sbt-web-scalajs-bundler/play fails

Tested on windows with command sbt "sbt-web-scalajs-bundler/scripted sbt-web-scalajs-bundler/play"

Error and trace:

[info] [info] Exception encountered when attempting to run a suite with class name: example.ExampleSpec *** ABORTED ***
[info] [info]   java.lang.NoClassDefFoundError: example/Routes (wrong name: example/routes)
[info] [info]   at java.lang.ClassLoader.defineClass1(Native Method)
[info] [info]   at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
[info] [info]   at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
[info] [info]   at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
[info] [info]   at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
[info] [info]   at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
[info] [info]   at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
[info] [info]   at java.security.AccessController.doPrivileged(Native Method)
[info] [info]   at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
[info] [info]   at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[info] [info]   ...
[info] [error] Uncaught exception when running example.ExampleSpec: java.lang.NoClassDefFoundError: example/Routes (wrong name: example/routes)
[info] sbt.ForkMain$ForkError: java.lang.NoClassDefFoundError: example/Routes (wrong name: example/routes)
[info]  at java.lang.ClassLoader.defineClass1(Native Method)
[info]  at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
[info]  at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
[info]  at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
[info]  at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
[info]  at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
[info]  at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
[info]  at java.security.AccessController.doPrivileged(Native Method)
[info]  at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
[info]  at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[info]  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
[info]  at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[info]  at example.ExampleComponents.<init>(Loader.scala:14)
[info]  at example.Loader.load(Loader.scala:8)
[info]  at example.ExampleSpec.app$lzycompute(ExampleSpec.scala:9)
[info]  at example.ExampleSpec.app(ExampleSpec.scala:8)
[info]  at org.scalatestplus.play.OneServerPerSuite$class.run(OneServerPerSuite.scala:176)
[info]  at example.ExampleSpec.org$scalatestplus$play$OneBrowserPerSuite$$super$run(ExampleSpec.scala:6)
[info]  at org.scalatestplus.play.OneBrowserPerSuite$class.run(OneBrowserPerSuite.scala:364)
[info]  at example.ExampleSpec.run(ExampleSpec.scala:6)
[info]  at org.scalatest.tools.Framework.org$scalatest$tools$Framework$$runSuite(Framework.scala:357)
[info]  at org.scalatest.tools.Framework$ScalaTestTask.execute(Framework.scala:502)
[info]  at sbt.ForkMain$Run$2.call(ForkMain.java:296)
[info]  at sbt.ForkMain$Run$2.call(ForkMain.java:286)
[info]  at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[info]  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
[info]  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
[info]  at java.lang.Thread.run(Thread.java:745)
[info] [info] ScalaTest
[info] [info] Run completed in 3 seconds, 60 milliseconds.
[info] [info] Total number of tests run: 0
[info] [info] Suites: completed 0, aborted 1
[info] [info] Tests: succeeded 0, failed 0, canceled 0, ignored 0, pending 0
[info] [info] *** 1 SUITE ABORTED ***
[info] [error] Error: Total 1, Failed 0, Errors 1, Passed 0
[info] [error] Error during tests:
[info] [error]  example.ExampleSpec
[info] [error] (server/test:test) sbt.TestsFailedException: Tests unsuccessful
[info] [error] Total time: 30 s, completed Nov 3, 2016 11:22:16 PM
[error] x sbt-web-scalajs-bundler / play
[error]    {line 10}  Command failed: server/test failed
java.lang.RuntimeException: Failed tests:
        sbt-web-scalajs-bundler / play

        at scala.sys.package$.error(package.scala:27)
        at sbt.test.ScriptedRunner.runAll(ScriptedTests.scala:156)
        at sbt.test.ScriptedRunner.run(ScriptedTests.scala:151)
        at sbt.test.ScriptedRunner.run(ScriptedTests.scala:125)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at sbt.ScriptedPlugin$$anonfun$scriptedTask$1$$anonfun$apply$3$$anonfun$apply$4.apply(ScriptedPlugin.scala:61)
        at sbt.ScriptedPlugin$$anonfun$scriptedTask$1$$anonfun$apply$3$$anonfun$apply$4.apply(ScriptedPlugin.scala:57)
        at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
        at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
        at sbt.std.Transform$$anon$4.work(System.scala:63)
        at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
        at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
        at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
        at sbt.Execute.work(Execute.scala:237)
        at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
        at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
        at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
        at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
[error] (sbt-web-scalajs-bundler/*:scripted) Failed tests:
[error]         sbt-web-scalajs-bundler / play

Transitive dependencies

Currently if we have a Scala.js project A that depends on an NPM package x, and another Scala.js project B that depends on A, B does not depend on the NPM package x.

Don't ignore webpack errors

At the moment any bunding errors are ignored by the webpack task.

Here's an example project. It contains an error (an unresolved module). But the webpack task succeeds!

$ sbt fastOptJS::webpack
<truncated>
[info] ERROR in ./js-resources-fastopt.js
[info] Module not found: Error: Cannot resolve module 'no-such-module' in /home/dmitry/work/various-examples/scala/sbt-scalajs-bundler/webpack-bail/target/scala-2.11/scalajs-bundler/main
[info]  @ ./js-resources-fastopt.js 1029:32-57
[success] Total time: 19 s, completed Jan 13, 2017 3:46:32 PM

The reason for this is a quirk of webpack itself: by default it always produces zero return code, even when errors are encountered. There are ways to change this behaviour, though: --bail command-line option and bail flag in configuration. I think scalajs-bundler should also expose this functionality, and/or fail on error by default.

Workaround: Setting bail config flag in a custom webpack config.

Custom loader script for nodejs

I'm trying to invoke my application via nodejs, however this requires me to pass a bootstrap struct

{
        "__dirname": __dirname,
        "__filename": __filename,
        "exports": exports,
        "module": module,
        "require": require
}

via a bootstrap javascript file (this is how transcendent does it), to my JSApp main function. I do this, so I can e.g. require modules like express from within my JSApp via the passed nodejs "require" function.

Only problem is that requiring the generated webpack bundle does not export a main fn, so I am unable to invoke it with the bootstrap struct. I suspect it would be possible to write a custom loader using sbt that invokes the JSApp.main() with the necessary struct - then that would be invoked upon requiring the webpack - but I'm wondering whether there is a simpler way?

`testHtmlFastOpt` and `testHtmlFullOpt` use incorrect file

The HTML that gets generated uses [name]-test-[stage].js vs [name]-test-[stage]-bundle.js. It looks like it's looking at fastOptJS in testHtmlFastOpt for the file name. I made a quick fix in my own project, and would contribute it back but I don't really see where the bundle is named. Obviously it's fairly hacky.

fastOptJS in testHtmlFastOpt in Test := {
      val f = (fastOptJS in testHtmlFastOpt in Test).value
      val fd = new File(f.data.getPath.stripSuffix(".js") + "-bundle.js")
      f.copy(fd)(f.metadata)
    }

Getting java.lang.IllegalStateException: Linker used concurrently

Using 0.3.0, I sometimes get:

> ~fastOptJS::webpack
[info] Compiling 1 Scala source to /home/naftoli/dev/gitlab.com/nafg/qbmeetup-tictactoe/target/scala-2.11/classes...
[info] Fast optimizing /home/naftoli/dev/gitlab.com/nafg/qbmeetup-tictactoe/target/scala-2.11/qbmeetup-tictactoe-fastopt.js
[trace] Stack trace suppressed: run last compile:fastOptJS for the full output.
[error] (compile:fastOptJS::webpack) java.lang.IllegalStateException: Linker used concurrently
[error] Total time: 3 s, completed Nov 30, 2016 1:30:23 AM

Here's my build.sbt:

name := "qbmeetup-tictactoe"

version := "1.0"

scalaVersion := "2.11.8"

enablePlugins(ScalaJSBundlerPlugin)

resolvers += Resolver.jcenterRepo

libraryDependencies += "io.github.nafg" %%% "sri-web" % "0.6.0-M1"

jsDependencies ++= Seq(
  "org.webjars.bower" % "react" % "15.3.1" / "react-with-addons.js" minified "react-with-addons.min.js" commonJSName "React",
  "org.webjars.bower" % "react" % "15.3.1" / "react-dom.js" minified "react-dom.min.js" dependsOn "react-with-addons.js" commonJSName "ReactDOM",
  "org.webjars.npm" % "history" % "3.0.0-2" / "history.js" minified "history.min.js"
)

fastOptJS::webpack fails on Scala JS 0.6.14

I am using bundler 0.4.0.

I have upgraded my app's Scala JS to 0.6.14, and I started getting the following error on fastOptJS::webpack.

[info] Fast optimizing /Users/shogowada/Projects/scalajs-reactjs/example/todo-app/target/scala-2.12/scalajs-bundler/main/scalajs-reactjs-example-todo-app-fastopt.js
[debug] Linker: Compute reachability: 102223 us
[debug] Linker: Assemble LinkedClasses: 55114 us
[debug] Basic Linking: 159919 us
[debug] Inc. optimizer: Batch mode: false
[debug] Inc. optimizer: Incremental part: 15126 us
[debug] Inc. optimizer: Optimizing 0 methods.
[debug] Inc. optimizer: Optimizer part: 165 us
[debug] Inc. optimizer: 26363 us
[debug] Refiner: Compute reachability: 160233 us
[debug] Refiner: Assemble LinkedClasses: 13323 us
[debug] Refiner: 173718 us
[debug] Emitter: Class tree cache stats: reused: 0 -- invalidated: 319
[debug] Emitter: Method tree cache stats: resued: 0 -- invalidated: 1489
[debug] Emitter (write output): 1095017 us
[debug] Global IR cache stats: reused: 117 -- invalidated: 88 -- trees read: 449
java.lang.NoSuchMethodError: org.scalajs.core.tools.javascript.Trees$VarDef.<init>(Lorg/scalajs/core/tools/javascript/Trees$Ident;Lorg/scalajs/core/tools/javascript/Trees$Tree;Lorg/scalajs/core/ir/Position;)V
        at scalajsbundler.util.JS$.let(JS.scala:73)
        at scalajsbundler.ReloadWorkflow$.writeFakeBundle(ReloadWorkflow.scala:53)
        at scalajsbundler.sbtplugin.ReloadWorkflowTasks$$anonfun$webpackTask$1.apply(ReloadWorkflowTasks.scala:22)
        at scalajsbundler.sbtplugin.ReloadWorkflowTasks$$anonfun$webpackTask$1.apply(ReloadWorkflowTasks.scala:18)
        at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
        at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
        at sbt.std.Transform$$anon$4.work(System.scala:63)
        at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
        at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
        at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
        at sbt.Execute.work(Execute.scala:237)
        at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
        at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
        at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
        at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
[error] (exampleTodoApp/compile:fastOptJS::webpack) java.lang.NoSuchMethodError: org.scalajs.core.tools.javascript.Trees$VarDef.<init>(Lorg/scalajs/core/tools/javascript/Trees$Ident;Lorg/scalajs/core/tools/javascript/Trees$Tree;Lorg/scalajs/core/ir/Position;)V

I believe this is because Scala JS has changed the parameter type of VarDef class from

  • (name: Ident, rhs: Tree)(implicit val pos: Position) to
  • (name: Ident, rhs: Option[Tree])(implicit val pos: Position)

starting from 0.6.14 (See scala-js/scala-js@6863451#diff-4d512422fde665c4c5d713d24ddd3bffR63 for the diff).

This blocks dependent apps to upgrade to Scala JS 0.6.14.

How to integrate with HTML?

I tried to recreate the official tutorial, but with scalajs-bundler in my repo. I compiled with sbt fastOptJS::webpack and opened the .html file. I got Uncaught TypeError: (0 , $m_Lorg_scalajs_jquery_package$(...).jQuery$1) is not a function.
Please provide an example with HTML files.

Add a conflicting dependencies resolution mechanism

This relates to #48.

We could introdue a new key resolutions that would allow leaf projects to specify how to resolve conflicting dependencies:

resolutions := Seq(
  "some-package" -> "1.2.3"
)

This information would be used to define which version to use in case of conflict.

This setting would not be stored in the artifact’s manifest, so project depending on a project that defines resolutions would not transitively get these resolutions.

Disable the reload workflow by default

(Also see #58 for some more context)

The “reload workflow” is a special mode that replaces the webpack task implementation with a different one, that does not use the webpack program to process the output of the Scala.js compilation. It has been implemented to get a faster “change source and reload application” workflow but a drawback is that it ignores any user supplied webpack configuration file. This behavior might be surprising so it is probably better to not enable it by default.

Another plugin for npm dependencies only

For some projects, it is usefull to only fetch the JSs (with npmUpdate) without webpacking all the JSs into one big js. Creating a plugin allowing js fetching without interfering in the full/fastOptJS build would be very great.

Incremental bundling

Bundling time can be ~30 s for a 5k sloc project (~10 s if we disable source maps).

Investigate ways to perform incremental bundling using webpack-dev-server.

Error on space in directory path

If there is a space in the directory path the compilation will fail.

Error log:

Error: Cannot find module 'C:\Dev'
    at Function.Module._resolveFilename (module.js:325:15)
    at Function.Module._load (module.js:276:25)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:139:18)
    at node.js:968:3

Add dependency metadata in jars

I assume the recursive dependencies must now be added manually.

It woule be nice if metadata about the npm dependencies would have been added to the jar in a file similar to JS_DEPENDENCIES used for webjars. Maybe it should be possible to disable in case the user wants to include it manually.

NPM dependencies

Hi,
I have two questions on NPM dependencies:

  1. is it possible to restrict the required files from the NPM source ? Something like:
"myNPM" -> theVersion / "dist/thisJS.js" 
  1. is it possible to embedd css too through the NPM dependencies ? For instance:
"myNPM" -> theVersion / "dist/thisCSS.css" 

Thanks !

Unable to run the `stage` task of a Play application that uses scalajs-bundler

java.io.FileNotFoundException: client/target/scala-2.11/client-opt-bundle.js.map (No such file or directory)
	at java.io.FileInputStream.open0(Native Method)
	at java.io.FileInputStream.open(FileInputStream.java:195)
	at java.io.FileInputStream.<init>(FileInputStream.java:138)
	at org.apache.ivy.util.ChecksumHelper.compute(ChecksumHelper.java:96)
	at org.apache.ivy.util.ChecksumHelper.computeAsString(ChecksumHelper.java:92)
	at com.typesafe.sbt.digest.SbtDigest$DigestStage$.computeChecksum(SbtDigest.scala:201)
	at com.typesafe.sbt.digest.SbtDigest$DigestStage$$anonfun$21.apply(SbtDigest.scala:209)
	at com.typesafe.sbt.digest.SbtDigest$DigestStage$$anonfun$21.apply(SbtDigest.scala:209)
	at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
	at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
	at scala.collection.immutable.List.foreach(List.scala:318)
	at scala.collection.TraversableLike$class.map(TraversableLike.scala:244)
	at scala.collection.AbstractTraversable.map(Traversable.scala:105)
	at com.typesafe.sbt.digest.SbtDigest$DigestStage$.versionedMapping(SbtDigest.scala:209)
	at com.typesafe.sbt.digest.SbtDigest$DigestStage$$anonfun$categorise$1$$anonfun$apply$6.apply(SbtDigest.scala:161)
	at com.typesafe.sbt.digest.SbtDigest$DigestStage$$anonfun$categorise$1$$anonfun$apply$6.apply(SbtDigest.scala:161)
	at scala.Option.orElse(Option.scala:257)
	at com.typesafe.sbt.digest.SbtDigest$DigestStage$$anonfun$categorise$1.apply(SbtDigest.scala:160)
	at com.typesafe.sbt.digest.SbtDigest$DigestStage$$anonfun$categorise$1.apply(SbtDigest.scala:159)
	at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
	at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
	at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
	at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:47)
	at scala.collection.TraversableLike$class.map(TraversableLike.scala:244)
	at scala.collection.AbstractTraversable.map(Traversable.scala:105)
	at com.typesafe.sbt.digest.SbtDigest$DigestStage$.categorise(SbtDigest.scala:159)
	at com.typesafe.sbt.digest.SbtDigest$DigestStage$.process(SbtDigest.scala:135)
	at com.typesafe.sbt.digest.SbtDigest$DigestStage$.run(SbtDigest.scala:110)
	at com.typesafe.sbt.digest.SbtDigest$$anonfun$digestStage$1$$anonfun$apply$2.apply(SbtDigest.scala:47)
	at com.typesafe.sbt.digest.SbtDigest$$anonfun$digestStage$1$$anonfun$apply$2.apply(SbtDigest.scala:46)
	at scala.Function$$anonfun$chain$1$$anonfun$apply$1.apply(Function.scala:24)
	at scala.Function$$anonfun$chain$1$$anonfun$apply$1.apply(Function.scala:24)
	at scala.collection.LinearSeqOptimized$class.foldLeft(LinearSeqOptimized.scala:111)
	at scala.collection.immutable.List.foldLeft(List.scala:84)
	at scala.collection.TraversableOnce$class.$div$colon(TraversableOnce.scala:138)
	at scala.collection.AbstractTraversable.$div$colon(Traversable.scala:105)
	at scala.Function$$anonfun$chain$1.apply(Function.scala:24)
	at com.typesafe.sbt.web.SbtWeb$$anonfun$projectSettings$44.apply(SbtWeb.scala:244)
	at com.typesafe.sbt.web.SbtWeb$$anonfun$projectSettings$44.apply(SbtWeb.scala:244)
	at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
	at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
	at sbt.std.Transform$$anon$4.work(System.scala:63)
	at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
	at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:228)
	at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
	at sbt.Execute.work(Execute.scala:237)
	at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
	at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:228)
	at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
	at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.