Code Monkey home page Code Monkey logo

sbt-rjs's Introduction

sbt-rjs

Build Status

Setup

An SBT plugin to perform RequireJs optimization.

To use this plugin use the addSbtPlugin command within your project's plugins.sbt file:

addSbtPlugin("com.github.sbt" % "sbt-rjs" % "2.0.0")

Your project's build file also needs to enable sbt-web plugins. For example with build.sbt:

lazy val root = (project in file(".")).enablePlugins(SbtWeb)

As with all sbt-web asset pipeline plugins you must declare their order of execution e.g.:

pipelineStages := Seq(rjs)

You can include your scripts into the web page with the conventional RequireJS setup. E.g.:

<script data-main="/javascripts/main.js"
        src="/lib/requirejs/require.js"></script>

WebJars are treated specially. If a path is referenced that is part of a path belong to a Webjar then the webjarCdn setting is used to translate it to the CDN. This is all fully automatic and provided as part of a buildWriter function. Furthermore if a .bin or -bin equivalent of the resource is available then it is used. The end result is that all WebJar sourced resources are located via a CDN along with their minified versions.

Options

RequireJs optimization permits build profiles to be declared that specify what needs to be done. A standard build profile for the RequireJS optimizer is provided. You are able to use and/or customize settings already made, and add your own. Here are a list of relevant settings and their meanings:

Option Description
appBuildProfile The project build profile contents.
appDir The top level directory that contains your app js files. In effect, this is the source folder that rjs reads from.
baseUrl The dir relative to the assets or public folder where js files are housed. Will default to "js", "javascripts" or "." with the latter if the other two cannot be found.
buildProfile Build profile key -> value settings in addition to the defaults supplied by appBuildProfile. Any settings in here will also replace any defaults.
dir By default, all modules are located relative to this path. In effect this is the target directory for rjs.
generateSourceMaps By default, source maps are generated.
mainConfig By default, 'main' is used as the module for configuration.
mainConfigFile The full path to the above.
mainModule By default, 'main' is used as the module.
modules The json array of modules.
optimize The name of the optimizer, defaults to uglify2.
paths RequireJS path mappings of module ids to a tuple of the build path and production path. By default all WebJar libraries are made available from a CDN and their mappings can be found here (unless the cdn is set to None).
preserveLicenseComments Whether to preserve comments or not. Defaults to false given source maps (see http://requirejs.org/docs/errors.html#sourcemapcomments).
webJarCdns CDNs to be used for locating WebJars. By default "org.webjars" is mapped to "jsdelivr".
webJarModuleIds A sequence of webjar module ids to be used.

Supposing that your application does not use "main.js" as its main entry point and instead uses app.js:

RjsKeys.mainModule := "app"

(note the absence of the file extension).

If you wish to add a property that this plugin does not provide, but is available to rjs then you can provide a map of additional properties. Supposing that you wish to specify the locale to be used:

import WebJs._
import RjsKeys._

...

buildProfile := JS.Object("locale" -> "en-au")

buildProfile is a JS.Object, a map of String -> JS values. WebJs.JS is required to be imported.

WebJs automatically converts common types, like strings, numbers, maps, and sequences, to the JS type. For example, given an example from the rjs documentation you can express:

import WebJs._
import RjsKeys._

...

modules += JS.Object("name" -> "foo/bar/bip", "exclude" -> Seq("foo/bar/bop"))

The plugin is built on top of JavaScript Engine which supports different JavaScript runtimes.

sbt-rjs's People

Contributors

benmccann avatar dgolubets avatar huntc avatar jroper avatar mebur avatar micmro avatar mkurz avatar muuki88 avatar oehnstro avatar pvlugter avatar richdougherty avatar scala-steward 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sbt-rjs's Issues

Update r.js dependency

I was wondering if it would be possible to update the r.js dependency to the latest version (2.1.15)?

Changing RjsKeys.modules key has no effect

When I set the RjsKeys.modules key to the following value:

RjsKeys.modules := WebJs.JS.Object("name" -> "foo")

I get the following error during the assets pipeline:

[info] Error: Error: /my-project/target/web/rjs/appdir/javascripts/main.js does not exist.

(note that it is looking for a main.js file instead of foo.js)

However, just changing the following works fine:

RjsKeys.mainModule := "foo"

Q: How to configure when app lives in sub-directory

Hi,

I have an app that lives in assets/javascripts/app1/main.js (in fact, this is a requirejs module)

Now when i solely use webjars-all is fine. In both production and development context, at least there are no complains about missing modules.

I needed to add a library from a local folder outside of of the mentioned folder. - Let's say its path is assets/javascripts/vendor/lib1/lib1.js.

In my main.js, i declare its path like this: 'ng-progress': '../vendor/ngProgress/ngProgress',

Now the problem is: The optimizer doesnt find it in the path. How would i override the build profile for this very library? Is there an example available somewhere?

Doc suggestions: disable CDN and include/exculde files

Code seems like it was intended for RjsKeys.cdn := None
but I had to do something like:
RjsKeys.webJarCdns := Map("Derp" -> "")

Also, I've had no luck with the include/exclude filters. These would be worthwhile docs: How do you chain them, and what path do they start at (top level)?

Source maps generated, although RjsKeys.generateSourceMaps=false is set

Using play 2.3.1.

My Build.scala looks like

val main = Project(appName, file(".")).enablePlugins(play.PlayScala).settings(
   scalaVersion := "2.10.4",
   version := appVersion,
   libraryDependencies ++= appDependencies,
   pipelineStages := Seq(rjs, digest, gzip),
   CoffeeScriptKeys.sourceMap := false,
   RjsKeys.generateSourceMaps := false,
   resolvers += "sbt-plugin-releases" at "http://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/",
   resolvers += "sonaype-snapshots" at "https://oss.sonatype.org/content/repositories/snapshots",
   scalacOptions ++= Seq("-feature", "-deprecation"),
   testOptions += Tests.Argument("-oDF")
 )

The dependencies contain

"org.webjars" % "requirejs" % "2.1.14-1",

and the plugin.sbt contains

addSbtPlugin("com.typesafe.sbt" % "sbt-coffeescript" % "1.0.0")

addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.1")

I created an empty main.js to make requireJs work, but I'm not using it. I'm accessing javascript files directly using their path/filename.

In dev mode, the sources are non-minified. Accessing path/file.js returns the non-minified output from the compiler.

Running the application in prod mode, it minifies the javascript sources correctly. Accessing path/file.js returns the minified javascript file. This is exactly what I want so far.

However, the browser also requests the source map path/file.js.src.js and the server delivers it.

Since I set CoffeeScriptKeys.sourceMap := false (see build file above), it doesn't deliver the coffee script file as source map anymore, but it still delivers the non-minified javascript file that is output by the coffeescript compiler. RjsKeys.generateSourceMaps := false doesn't seem to make a difference.

Attempting to remove cdn using config and getting error

I have the following config:

RjsKeys.appBuildProfile := JS.Object(
"appDir" -> RjsKeys.appDir.value,
"baseUrl" -> RjsKeys.baseUrl.value,
"dir" -> RjsKeys.dir.value,
"generateSourceMaps" -> RjsKeys.generateSourceMaps.value,
"mainConfigFile" -> RjsKeys.appDir.value / RjsKeys.mainConfigFile.value.getPath,
"modules" -> RjsKeys.modules.value,
"optimize" -> RjsKeys.optimize.value,
"preserveLicenseComments" -> RjsKeys.preserveLicenseComments.value,
"removeCombined" -> RjsKeys.removeCombined.value
)

This produces error - Error: Error: Module loading did not complete for: ....

However when I run separately r.js directly on the app.build.js everything works.

Please help.

Plan to support CDN for css

Do you have any plan to support CDN for css as well? So far I can get the css to optimize with @import in main.css, but I think it would be cool if we can go a step further by replacing webjar css with the CDN version.

sbt-rjs-plugin-tester can not even build RequireJS projects

I could not get sbt-rjs working in my own project so I tried building sbt-rjs-plugin-tester

So I tested running sbt compile from the sbt-rjs/sbt-rjs-plugin-tester directory and I do not even get a
sbt-rjs/sbt-rjs-plugin-tester/target/web directory.

I have node installed so the build.sbt is unchanged.

I have tried both master and 1.0.8

Rewrite doesnt work properly

In my main.js, I have included a library:

requirejs.config({
//..
paths: {
//..
'angular-ui-select': '../../bower_components/angular-ui-select/dist/select.min',
//..
}
});

In the build.js, it is being externalized via empty:.

What happens is that on processing, the resulting file that is delivered in production is

function..... (the libraries content)
define("angular-ui-select", ["angular"], (function (global) {
    return function () {
        var ret, fn;
        return ret || global.angular;
    };
}
..

As you can see, the wrapper is not generated around, but after the libraries' content.

Am I missing something or is this a bug?

File.separator (produced by "withSep" method) used in regexp does not work in Windows

"$lib" variable is expanded to "lib" in
https://github.com/sbt/sbt-rjs/blob/master/src/main/scala/com/typesafe/sbt/rjs/SbtRjs.scala#L136 in Windows OS because java.io.File.separator is "".

This causes:

java.util.regex.PatternSyntaxException: Unmatched closing ')' near index 47
['"]?([^\s'"])['"]?\s:\s_[[]?.['"]./lib(._)['"]
^
at java.util.regex.Pattern.error(Pattern.java:1924)
at java.util.regex.Pattern.compile(Pattern.java:1669)
at java.util.regex.Pattern.(Pattern.java:1337)
at java.util.regex.Pattern.compile(Pattern.java:1022)
at scala.util.matching.Regex.(Regex.scala:153)
at scala.collection.immutable.StringLike$class.r(StringLike.scala:224)
at scala.collection.immutable.StringOps.r(StringOps.scala:31)
at scala.collection.immutable.StringLike$class.r(StringLike.scala:213)
at scala.collection.immutable.StringOps.r(StringOps.scala:31)
at com.typesafe.sbt.rjs.SbtRjs$$anonfun$getWebJarPaths$1$$anonfun$apply$5.apply(SbtRjs.scala:136)

Backslash (java.io.File.separator in Windows) should be escaped or replaced with slash (I don't know which solution will work).

mainConfig not working

I have a project that looks like this that uses babel to transpile js so that it's compatible with requirejs. I looked at the test project and followed that example. But when i visit this in the browser I get.

"require.min.js:5 Uncaught Error: Script error for "react", needed by: main"

Have I missunderstood how I get rjs to load the build.js config?

build.sbt

...
import WebJs._
import RjsKeys._
pipelineStages := Seq(rjs)
RjsKeys.mainConfig := "common"
...

app/assets/javascripts/common.js

requirejs.config({
    paths: {
        'react':                    '../bower_components/react/react-with-addons.min',
        'react-dom':            '../bower_components/react/react-dom.min',
...
    }
});

app/assets/javascripts/main.js

import ReactDOM from 'react-dom';
import Spinner from 'components/spinner';

const App = React.createClass({displayName: "App",
    render: function() {
        let page = <Spinner />;

        return (
            <div>{page}</div>
        );
    }
});

ReactDOM.render(
    <App />,
    document.getElementById("container")
);

index.scala.html

...
<script data-main='@routes.Assets.versioned("javascripts/main.js")' src='@routes.WebJarAssets.at(WebJarAssets.locate("require.min.js"))' type='text/javascript'></script>
...

transpiled main.js

(function (global, factory) {
    if (typeof define === "function" && define.amd) {
        define(['react-dom', 'components/spinner'], factory);
    } else if (typeof exports !== "undefined") {
        factory(require('react-dom'), require('components/spinner'));
    } else {
        var mod = {
            exports: {}
        };
        factory(global.reactDom, global.spinner);
        global.main = mod.exports;
    }
})(this, function (_reactDom, _spinner) {
    'use strict';

    var _reactDom2 = _interopRequireDefault(_reactDom);

    var _spinner2 = _interopRequireDefault(_spinner);

    function _interopRequireDefault(obj) {
        return obj && obj.__esModule ? obj : {
            default: obj
        };
    }

    const App = React.createClass({ displayName: "App",
        render: function () {
            let page = React.createElement(_spinner2.default, null);

            return React.createElement(
                'div',
                null,
                page
            );
        }
    });

    _reactDom2.default.render(React.createElement(App, null), document.getElementById("container"));
});

sbt-rjs fails without packaging failing

With sbt-web 1.1.1, rjs 1.0.7, and
pipelineStages := Seq(rjs, digest, gzip),
and no main.js, the result of packaging is that there is an error in the console, but a package is produced. Assets are subsequently broken when the resulting package is deployed.

The issue is that without a main.js, we get a message to console:
[info] Error: Error: /home/patrick/npl/auvik/target/web/rjs/appdir/javascripts/main.js does not exist.

It may be better if the packaging failed immediately, as the assets don't display once installed.

Sidenote: if the support is there within sbt-web's js engine, it might help if a similar log output format is used - some build tools might miss Error: Error: while they might be able to report [error] as a task failure when packaging.

Thanks Christopher!

Is sbt-rjs dead?

Clearly a lot of people use sbt-rjs but why is it not maintained. The build is broken when looking at Travis. Why are not the pull request even looked at? 4 months and no new release on this?

In this post you want people to to try sbt-rjs with sbt 1.4 sbt/sbt-web#118. Sbt-web 1.4.0 and sbt-rjs 1.0.8 does not work together.

Is this project dead?
Do you need help?
#66 #68 #69 #71 #75

@huntc @jroper

removeCombined doesn't have any affect

Hi,
I'm using sbt-rjs 1.0.7 with play 2.5.8.

my build.sbt contains:

pipelineStages := Seq(rjs)
RjsKeys.mainConfig := "main"

and my main.js contains this configuration:

requirejs.config({
        baseUrl : "/assets/scripts/",
        paths: {

        },
        generateSourceMaps : true,
        removeCombined : true
    });

Although removeCombined is set to true I can still fetch the *.js.src.js files and the mapping files too.

Is it a bug or misconfiguration?

Thanks

Allow for dynamic listing of modules

It would be very nice if RjsKeys.modules was TaskKey rather than a SettingKey so that we could dynamicly build the configuration.

Background

In our use case we have one "view" js.file per page and during development we want to dynamically load them for short turnaround times but for production we want to concatenate them into one js-file.

Since we do not want to load everything for every page during development we cannot list the "views" as dependencies in our main.js. We would like to avoid having to have to manually list those in an empty module since it would be easy to forget and wouldn't be noticed until run in deployment.

If module was a task key we could traverse our file structure and generating modules on the fly based on what files are available in our js codebase.

Clarify docs for getting started

Thanks for the plugin. I wanted to check it out to see the way you guys develop JS. Some questions I have trying to get it to work:

* At what URL is the optimized JS available from?
* How does it work in development mode? Does it not run the optimization and I need to include an extra script in my page?

Regex Exception thrown when the mainModule option is set.

As my app uses app.js as a main entry point, I set the mainModule option as the document suggests. However, I got the following exception when I executed dist command.

[trace] Stack trace suppressed: run last *:rjsPaths for the full output.
[error] (*:rjsPaths) java.util.regex.PatternSyntaxException: Unmatched closing '
)' near index 47
[error] ['"]?([^\s'"]*)['"]?\s*:\s*[\[]?.*['"].*/lib\(.*)['"]
[error]                                                ^

Below is the build.sbt file.

import RjsKeys._

name := """play-angular-phonecat"""

version := "1.0-SNAPSHOT"

libraryDependencies ++= Seq(
  "org.webjars" % "jquery" % "1.11.1",
  "org.webjars" % "bootstrap" % "3.1.1",
  "org.webjars" % "angularjs" % "1.2.16" exclude("org.webjars", "jquery"),
  "org.webjars" % "requirejs" % "2.1.11-1"
)     

lazy val root = (project in file(".")).enablePlugins(PlayScala, SbtWeb)

pipelineStages := Seq(rjs, digest, gzip)

RjsKeys.mainModule := "app"

sbt-rjs + submodules => no concatenation

hi,

i am working on a play 2.3 project using webjars and which has a submodule.
i am trying to use sbt-rjs to concatenate and minify different modules which are specified in my javascripts/main.js (which i tested in the angular seed project where it worked).

the optimization runs through without errors but in my project the modules wont' be concatenated.

any ideas?
'''
(function(requirejs) {
'use strict';

requirejs.config({
    "modules": [{
        "name": "export" //, ...
    }, {
        "name": "public" //, ...
    }, {
        "name": "settings" //, ...
    }],
    "paths": {
        "angular": "../lib/angularjs/angular",
        "angular-route": "../lib/angularjs/angular-route",
        "bootstrap": "../lib/bootstrap/js/bootstrap",
        "d3": "../lib/d3js/d3" //, ...
    },
    "shim": {
        "angular": {
            "deps": ["jquery"],
            "exports": "angular"
        },
        "bootstrap": {
            "deps": ["jquery"]
        },
        "d3": {
            "exports": "d3"
        } //, ...
    }
});
require(["public"], function() {});

})(requirejs);
'''

Q: How to access digest'ed submodules

I have a project with multiple sub-modules

assets/javascript/project1
  - module1/main.js
  - module2/main.js
  - main.js

The files build fine, but how can i trick requirejs into loading the digested' submodules?
Right now it loads the module1/main.js instead of module1/hash-main.js

The submodules are defined per

RjsKeys.mainModule := "main"

RjsKeys.baseUrl := "javascripts/project1"

RjsKeys.modules := Seq(
  WebJs.JS.Object("name" -> "module1"),
  WebJs.JS.Object("name" -> "module2"),
  WebJs.JS.Object("name" -> "module3")
  ...
)

No logging output

The plugin doesn't provide any progress information. It's impossible to figure out if
sbt crashed or the optimization is still running (and at which point it currently is).

Reproduce with

activator new angular-seed-play
activator

I also tried set logBuffered := false

Allow to hide source maps in prod mode (and still show them in dev mode)

I want source maps to be available in dev, but not in prod.
If this is not the default behavior you want, you could introduce this as a config option.

Many play apps are using different application.conf for dev and prod. If the availability of source maps could be configured using a key in application.conf, people could easily switch off source maps in prod environment.

I don't mind about the performance of building source maps in prod. I'm fine with always building source maps, but only making them available to the browser if the app is in dev mode.

Connected: sbt/sbt-coffeescript#5

wrong configuration option in README.md

Hello

Thanks for your work, I need plugin like this one very much.

I'm trying to start work with plugin, but I can't run plugin.
It looks like the string

addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.0-RC3")

is defenitely wrong. I always receive from sbt this:

[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: com.typesafe.sbt#sbt-rjs;1.0.0-RC3: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::

I tryed RC4, RC5, 1.0.0, 1.0.1, nothing works.
Would you fix docs pls.

Thanks,
Andrey.

Files not being concatenated before optimization

What I expect

I believe the way this is supposed to work is that with "play run" all the js is loaded in as it appears in my editor and with "play start" all the files are supposed to be concatenated together and then optimized.

What actually happens

When I do "play run" and when I do "play start" my main.js looks exactly the same in both instancess with each file being optimized independently. I would think no optimization should happen in dev mode and that in prod mode that there would be some concatenation happening first.

My setup

I see that SbtRjs is enabled in my project and I've also set "pipelineStages := Seq(rjs)". I'm not sure what else to look into. I see another open bug for adding logging. It seems like that would be helpful here as well so that I could enable debug logging since the plugin seems to not be working for me

$ sbt about
[info] Available Plugins: sbt.plugins.IvyPlugin, sbt.plugins.JvmPlugin, sbt.plugins.CorePlugin, sbt.plugins.JUnitXmlReportPlugin, play.Play, play.PlayJava, play.PlayScala, play.twirl.sbt.SbtTwirl, com.typesafe.sbt.jse.SbtJsEngine, com.typesafe.sbt.jse.SbtJsTask, com.typesafe.sbt.web.SbtWeb, com.typesafe.sbt.webdriver.SbtWebDriver, com.typesafe.sbt.rjs.SbtRjs, com.typesafe.sbt.less.SbtLess, com.typesafe.sbteclipse.plugin.EclipsePlugin, org.sbtidea.SbtIdeaPlugin, com.typesafe.sbt.SbtNativePackager

Debugging

It seems I need to delete the following directory to cause it to try to optimize again.

target/streams/$global/rjs/$global/streams/rjs

Once I do that I can get it to say "Optimizing JavaScript with RequireJS", but my main.js still isn't actually optimized

Uglify doing a lot of extra work

I noticed that uglify is doing quite a bit more than it needs to. I believe that it really only needs uglify the rjs optimized file. However, it is also uglifying all the source files as well, which makes compiling take longer than necessary.

hasjs is ignored

I am using hasjs for some conditional logic and I noticed that the 'has' config is being ignored. Below is my build.js file. Any idea how I can have hasjs working.

requirejs.config({ 
    'paths': { 
        "underscore": "libs/underscore/Underscore-1.6.0", 
         "has":"libs/misc/has"
    },
    has: {
        dev: false,
        mixpanel:true
    },
    modules: "main",
}); 

almondjs support

Hi,

I would love to have almondjs support in this. Is that possible?

sbt-rjs hangs

I had a weird behaviour in my environment, namely the build simply hanged (did not finish, no CPU usage) using tasks assets or run.
My environment is Play 2.6, sbt 1.2.8, sbt-rjs 1.0.10. I can provide a test project if needed.

Initially I thought it's a compatibility problem, tried to build sbt-rjs against newer stuff, like sbt 1.0.1, js-engine 1.2.3, but with no success.

I discovered that the problem was actually this line in my build.sbt:

pipelineStages in Assets := Seq(rjs)

I have no clue why this happens, tried to look at some debug logs (starting sbt with sbt -debug), and did not find anything. Apparently when running assets, sbt first executes update and then hangs. It may be that the cause is not in sbt-rjs.

Does not work with sbt-web 1.4.0

It works fine with 1.3.0 but with 1.4.0 i get this:

sbt cronusw/web-stage [info] Loading global plugins from /home/codeape/.sbt/0.13/plugins [info] Loading project definition from /home/codeape/src/git/cronus/project [info] Set current project to cronus (in build file:/home/codeape/src/git/cronus/) java.lang.NoSuchMethodError: com.typesafe.sbt.web.SbtWeb$.syncMappings(Ljava/io/File;Lscala/collection/Seq;Ljava/io/File;)Ljava/io/File; at com.typesafe.sbt.rjs.SbtRjs$$anonfun$runOptimizer$1$$anonfun$apply$9.apply(SbtRjs.scala:177) at com.typesafe.sbt.rjs.SbtRjs$$anonfun$runOptimizer$1$$anonfun$apply$9.apply(SbtRjs.scala:172) 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:226) at com.typesafe.sbt.web.SbtWeb$$anonfun$projectSettings$44.apply(SbtWeb.scala:226) 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] (cronusw/*:webPipeline) java.lang.NoSuchMethodError: com.typesafe.sbt.web.SbtWeb$.syncMappings(Ljava/io/File;Lscala/collection/Seq;Ljava/io/File;)Ljava/io/File; [error] Total time: 0 s, completed Oct 12, 2016 2:22:04 PM

Handle module dependencies in multi-project builds

Here's an example project illustrating the problem: https://github.com/JasonStoltz/sub-module-example

The project has has a root project with two sub-projects as dependencies.

/public 
  main.js <-- parent module
/modules 
  core/
    public/
      core.js <-- module declared in sub-project
  common
    public/
      common.js <-- module declared in sub-project

And in main.js, we have:

require(['core', 'common'], function(core, common){
...
}

From what I can tell, play handles this, but not sbt-rjs.

If you run activator run on that project and navigate to localhost:9000 ... no problems. Assets from all of the projects are available to the Assets controller under the same relative path, so the require works fine.

However, if you run web-stage, rjs optimization will choke on the require because it can't find 'common' ... "ENOENT, no such file or directory". That's because common.js is outside of the project's "mappings" in the asset pipeline.

Ideally, the rjs plugin would be able to include modules defined in sub-projects in it's optimization.

Publish for SBT 1.0

All the other plugins I use have already been updated, but since this one isn't, I can't use them (because the sbt-js-engine / sbt-web versions will be overruled). ๐Ÿ˜•

Would appreciate if someone could pick this up, tried it myself by looking at the changes in the other plugins, but there were a few things I couldn't work out.

edit
I can't even update to the latest version of the Play framework anymore, since it creates the same conflicts as above.

mainConfig File cannot be found

Hi,

I am struggling with the mainConfigFile parameter. It is not clear where the file is drawn from.

[info] RequireJS optimization has begun...
[info] app.build.js:
[info] ({appDir: "javascripts",
[info]           baseUrl: ".",
[info]           dir:"javascripts-min", mainConfigFile: "javascripts/shim.js", modules: [{name: "adventure"},{name: "adventurePublic"},{name: "index"},{name: "indexCat"},{name: "indexNew"},{name: "indexVet"},{name: "inspiration"},{name: "landing"},{name: "user"},{name: "static"}]})
[info] 
Error: .../app/target/scala-2.11/classes/public/javascripts/shim.js does not exist.
[info] RequireJS optimization finished.

(removed private paths)

Obviously, r.js uses a subfolder in the target folder (specifically "scala-2.11/classes/public") to find the config files. The folder is empty.
With the new sbt-web plugin structure, files seem to go to target/web/public/main/javascripts.

How can I influence which actual mainConfig file is picked? I also tried the mainConfigFile parameter which didn't affect the process at all.

Thx & cheers
Michael

How to perform an independent RJS optimization for a sbt subproject

Hi,

I was wondering if someone could help me to figure out how to configure RequireJS in my case. I have this seed template that has a root sbt project with two main subprojects: web (for users) and admin. Each subproject has it's own configuration (pipelineStages and RjsKeys.mainModule) and I currently can run and dist them as independent subprojects and they work perfectly. You can check the build.sbt and Common.scala files to see the configuration.

The problem is that I would like to be able to dist the root project as well. Then, I would need to perform the RequireJS optimization for each subproject independently, but I can't. It only happens for the root project itself, so it requires me to implement an only one build configuration as a whole project.

So then, is there any option to perform an independent RequireJS optimization for each sbt subproject?

Thanks!

Heroku doesn't find stylesheets and JS when using RJS

Hi,

Thanks for your plugin!

I'd like to draw your attention to this question and answer on Stack Overflow:
https://stackoverflow.com/questions/26999365/play-framework-2-3-6-java-javascripts-and-stylesheets-not-found-when-deployed

I'm not the author but I had the exact same problem that could be solved by replacing sbt-rjs with sbt-uglify, as mentioned in the question's answer.

Is there some kind of incompatibility between sbt-rjs and Heroku?

I'm using sbt-rjs 1.0.7.

Let me know if I can provide any more detail on the issue.

Thanks in advance!

What is supposed to happen in sbt-rjs-plugin-tester?

I've been trying to use this plugin to run the require optimizer to produce a single .js file. I see from another issue that that isn't supported.

What I can't figure out is what this actually does. I did "assets", "package", and "packageBin" in that project and then examined the output in target/web/public. Of the files that are in there, I couldn't find a single one that was any different from the source files.

What should I expect to see when this is working directly. I think that I must just be either thinking about or using this plugin incorrectly.

[?] External build profile

How am I supposed to supply an external build.js file, for instance? Can I (somehow) configure sbt-rjs to use an external build profile or I really have to translate everything to scala JS.Object syntax?

Thanks in advance

NPM webjars are not supported

The CDN path replacement strategy is not working for npm and npmcdn.com as the path patten is not the same as jsdeliver.

Sources from src/main/public are optimized.

Say I have the following directory structure:

src
โ””โ”€โ”€ main
    โ”œโ”€โ”€ assets
    โ”‚ย ย  โ””โ”€โ”€ js
    โ”‚ย ย      โ””โ”€โ”€ main.js
    โ””โ”€โ”€ public
     ย ย  โ””โ”€โ”€ js
     ย ย   ย ย  โ””โ”€โ”€ other.js

When running web-stage, the file other.js is also optimized:

> web-stage
[info] Optimizing JavaScript with RequireJS
[info] 
[info] Tracing dependencies for: main
[info] Uglify2 file: ./target/web/rjs/build/js/main.js
[info] Uglify2 file: ./target/web/rjs/build/js/other.js

Is this intended like this? I would have expected that all resources from src/main/public are just copied over to target/web/stage and not go through the asset pipeline.

webJarModuleIds setting not work

There is an inconsitency in documentation.

webJarModuleIds setting is not configurable since the key is missing in the plugin.

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.