Hello, everyone.
After some research about the build process of a Vaadin app, I come to this forum with no luck so far to solve the situation I’m in. I was trying to generate a production build of a spring app, which unfortunately I can’t get to work properly.
The problem goes like this:
- I have a vaadin-spring project, from which I am trying to build a WAR to deploy on a Tomcat server. (At first, I thought the problem was here, because by default, the project starter is configured to build a JAR - I set up additional configuration to build a WAR - But this is not the case, as I describe below).
- When I run the project in development mode, the Javascript imports appear to be all good and sorted in the same way as my annotations.
- But, when I build the project for production with
mvn clean package -P productionMode
, the scripts are now bundled and with different order to which I described in myMainView
(I tried disabling transpilation and minification, but results were no different). - This leads to some code that depends on another, to be loaded first, without its dependencies being loaded yet.
- So, when the users access the server, the Javascript plugins are not shown.
For example, I want these libraries in my project (and in this same order):
- [ChartsJS]
(https://www.chartjs.org/) - [jQuery]
(https://jquery.com/) - [JSMaps]
(https://jsmaps.io/)
But, the bundle loads first JSMaps, then ChartsJS and finally jQuery, breaking JSMaps which depends on jQuery.
I know a solution could be to place all of the JS inside a single JS file, but I don’t think that’s the way to go.
I’m pretty sure the problem is not because of additional configuration in my project, as I was able to replicate the behavior in a fresh starter template for vaadin-spring.
The order in which annotations describe the Javascript to be loaded is as follows
@JavaScript("js/charts.js")
@JavaScript("js/jquery.js")
@JavaScript("js/jsmaps/jsmaps-libs.js")
@JavaScript("js/jsmaps/jsmaps.js")
@JavaScript("js/maps/mexico.js")
But the bundled versions for ES6 and ES5 load the files in ALMOST a reverse order.
mexico.js
jsmaps.js
jquery.js
jsmaps-libs.js
charts.js
Maybe I’m missing something trivial, but I’d rather learn from this instead of doing a dirty solution.
I’ve attached the project on which I was able to replicate the behavior (it must be imported as an Existing Maven Project in Eclipse).
Steps:
- When I run the project from Eclipse I can see the libraries loaded correctly in the browser.
- But, after I execute
mvn clean package -P productionMode
from the command line, inside the generated JAR, the bundles can be accessed just to confirm that the dependencies are being loaded in a weird way. You should try opening them to see the logs I added to the console, as they show the order on which the libraries are being loaded.
Thanks to everyone. I appreciate any comment or suggestion.
17461261.rar (264 KB)