I have had some promising results using the com.google.code.maven-replacer-plugin. Here is a summary of my progress:
Initially, I encapsulated my styles and scripts with designated "markers":
<!-- replaceCSS -->
<link rel="stylesheet" href="styles/app/01.css">
<link rel="stylesheet" href="styles/app/02.css">
<link rel="stylesheet" href="styles/app/03.css">
<!-- replaceCSSEnd -->
...
...
...
<!-- replaceJS -->
<script src="scripts/01.js"></script>
<script src="scripts/02.js"></script>
<script src="scripts/03.js"></script>
<!-- replaceJSEnd -->
In addition, I included the plugin in my pom file:
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<file>target/${project.build.finalName}/app/index.html</file>
<replacements>
<replacement>
<token>(?m)<!-- replaceCSS(.|\s)*?replaceCSSEnd --&</token>
<value><link rel="stylesheet" type="text/css" href="styles/styles.css"/&></value>
</replacement>
<replacement>
<token>(?m)<!-- replaceJS(.|\s)*?replaceJSEnd --&></token>
<value><script src="scripts/scripts.js"/&></value>
</replacement>
</replacements>
</configuration>
</plugin>
During the build process or when testing with mvn replacer:replace, an exception occurs indicating something like:
at java.util.regex.Pattern$BranchConn.match(Pattern.java:4568)
Interestingly, this issue only arises when both replacement tags are present. If I remove one for the CSS files, the operation succeeds without any problems.
Furthermore, it seems that the replacement occurs after the packaging of the WAR file, which is clearly incorrect.