Often node servers have an option to redirect all pages not matching any resource (js, css) to index.html which will handle the routing. Typically you'll get this: # standard hash routing This solution consists to replace the hash routing by a more natural routing without hash. This solution works fine but one case is not handled: html5 routing.
#Archiver npm archive
We add to the archive (so the war) all the context of dist/application as root web resources of the war ( dest) We redirect the archive content to the output stream of our war We log some message when the war is done (never forget to let the user know you did something in a script) We create an output stream for our war and an archive handler ( archive) We want to build our war in dist/application.war
#Archiver npm zip
To create a zip we'll use archiver dependencies of npm: ]) (optional) map some urls in web.xml and add the web.xml in WEB-INF of the archive (more about this step in next part)įrom now on I'll only deal with parts 2 and 3 cause 1 is highly dependent on your application and 100% related to your javascript build.create a zip containing as root resources the SPA (web) resources.build your application (webpack, gulp.A war is after all just a zip with some specific files, right? Concretely you need to follow these high level steps: The easiest way is to build it through a script npm can launch. reuse an existing tooling around war deployment or monitoring you don't have yet around nodejs deployments (got this case for cluster deployment for instance).reuse an established stack ("deploy in tomcat").colocalizing the SPA with another application to save memory or process to manage.you already have a servlet container you control but you don't control a front (not there or just there as proxy).This is probably justified by the fact you often embed a single page application (SPA) in a java application but rarely the opposite.normally.Ī SPA is after all just a static website so nothing should prevent it to be served from a Servlet container. Where you easily find java (maven/gradle) plugin to build a frontend project, the opposite is rare. NPM is the standard to orchestrate a javascript build, even delegating front dependencies to bower or the build itself to gulp or webpack, the starting point is often npm. , Romain Manni-Bucau,, 5 min and 4 sec read