Auto rebuild closure soy templates

1.1k Views Asked by At

I faced a problem while using Google Closure Soy templates. When I change a template I need to run a script from command line to compile Soy template to JS file. Is there a service or something else to rebuild these templates automatically?

Also, as far as I know, "plovr" service is able to rebuild JS sources with closure compiler automatically. Is there a way to rebuild soy templates and put them to specified folder by plovr automatically?

1

There are 1 best solutions below

2
On

Plovr will automatically compile Closure Templates (soy files) along with JavaScript sources.

If your project had the following file structure, you could use the plovr config file shown below.

/home/my/project
         |-- build
         |-- js
             |-- myapp.js
         |-- soy
             |-- mytemplate.soy

plovr_config.json

{
  "id": "myapp",
  "inputs": [
    "/home/my/project/js/myapp.js"
  ],
  "paths": [
    "/home/my/project/soy"
  ],
  "mode": "ADVANCED",
  "level": "VERBOSE",
  "output-file": "/home/my/project/build/myapp.compiled.js"
}

During development, you would configure a <script> tag in your HTML file to automatically recompile your JavaScript and Closure Templates after launching the plovr server:

java -jar plovr.jar serve plovr_config.json 

index.html

<!doctype html>
<html>
<head>
  <title>My App</title>
</head>
<body>

<h1>My App</h1>

<script src="http://0.0.0.0:9810/compile?id=myapp"></script>

</body>
</html>