Play framework 2.3 dist task - javascripts-min not available

My PlayFramework (2.3) application works without problems when starting in development mode (sbt launch). However, when I try to create a distribution (sbt dist) or star production (sbt start), javascript files are executed in the minification folder (javascripts-min), which is not available. On the other hand, if you use sbt-uglify, it creates a smaller version of javascripts, but in the same directory (main.min.js and main.js).

GET http://localhost:9000/assets/javascripts-min/main.js 404 (Not Found) GET http://localhost:9000/assets/javascripts/main.js (Ok) 

Maybe I need to tweak something to minimize this. Should I include some sbt plugin or change application configuration?

+5
source share
2 answers

I ran into the same problem and for me the problem was that in the .scala.html file where I was loading the JavaScript file, I used @helper.requireJs as follows:

 @helper.requireJs(core = routes.Assets.at("javascripts/require.js").url, module = routes.Assets.at("javascripts/main.js").url) 

In Play Framework 2.3, either @helper.requireJs or it is deprecated, but it does not seem to work correctly. Replacing it with a regular <script> element solved the problem for me:

 <script src="@routes.Assets.at("javascripts/require.js").url" data-main="@routes.Assets.at("javascripts/main.js").url"></script> 
+6
source

You can use the productionFolderPrefix parameter to specify the postfix of the folder, use "" if you don't want to. (The parameter name is somewhat misleading, though)

For instance:

 @helper.requireJs(core = routes.Assets.at("javascripts/require.js").url, module = routes.Assets.at("javascripts/main.js").url, productionFolderPrefix = "") 

See requireJs # apply () doc or source code for help

0
source

Source: https://habr.com/ru/post/1200657/


All Articles