maven plugin to wrap html fragments into a javascript template used by angular js client
You often have many small html files if angular js is used. Minimization exists for js/css. We also need such tool for htmls. This is particular useful if your html templates are used in UI library. One such example is UI Bootstrap. For exmaple, bootstrap UI has many small fragments as template. The final distribution is a single javascript file with all these htmls. This plugin consolidates html files into angular js template. It is built into maven compile phase.
Add this fragement to your pom
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupid> <artifactId>maven-compiler-plugin</artifactid> </plugin> <plugin> <groupId>com.flexdms</groupid> <artifactId>htmltemplate-maven-plugin</artifactid> <version>1.0.2-SNAPSHOT</version> <configuration> <srcDirectory>src/main/webapp/fragments</srcdirectory> <finalFile>src/main/webapp/js/prop.js</finalfile> </configuration> <executions> <execution> <goals> <goal>merge</goal> </goals> <phase>compile</phase> </execution> </executions> </plugin> </plugins> </build>
Three parameters are available.
- srcDirectory: source directory. File are searched recursively. All Files found are processed.
- finalFile: where to output Javascript file.
- templateFile: optional. If omitted, internal template is used.
- fileHeader: header string in the final file.
- fileFooter: footer string in the final file
- generateModule: whether to generate module statement.
- process: whether to escape html to make it appear as valid json string. Default true. If false, text is copied without ang modification.
Please run mvn test to see an example. Test set up is under src/test/resources/unit directory. Final file is writtern to target/final.js or target/final2.js