Compiling JavaScript on Serverside With Scala and ScalaJS using Google Standard App Engine
Since my experience with the JavaScript world and exploration of ScalaJS I felt compelled to move from Node and Grunt and try to fully utilize Scala for both front and back.
I reached a goal with Scala Stack, a concept of creating all web content on serverside using only Scala code. The concept is extended to keep everything in code including configuration to be fully testable.
Obvious Advantages
My main purpose was to skip the JavaScript world but it moved on to something much larger. If all code is shared there are quite a few advantages
- Single, isomorphic source which ease work and can share logic
- Share data by keeping it in code. For instance languages could be defined with a Enum type
- Fully testable code
- No JavaScript package manager like NPM or WebPack
- No pre processor like Gulp or Grunt
- No SBT since the compilation is with a simple Servlet
Risks
There are some traps though
- Security, some code should not be shared between backend and frontend
- Long term effects, demands an experienced architect
- Shared code needs to be ScalaJS compatible and cannot use backend dependencies since it's compiled and used on frontend
Scala Stack
Map of Scala Stack |
I've made three implementations using Google Standard Environment with Java 8. Implemented in native JavaScript, jQuery and AngularJS.
Goal is to keep everything in code and to avoid configuration, annotations and settings in Strings.
By only using Scala on serverside, it produce HTML, CSS and JavaScript which is all components for a webpage.
Scala Stack with Angular
You find links to code and running example below
Servlet Compiler
Scala Stack is using a Servlet compiler with different logging:
- https://github.com/AIMMOTH/scala-js-compiler
- Jetty https://github.com/AIMMOTH/scalajs-compiler-servlet
Inga kommentarer:
Skicka en kommentar