我想使用 maven-replacer-plugin 在我的 index.html 文件中重命名我的 javascript 导入语句。
但是,我只想在路径以 app
开头的地方执行此操作
index.html 片段
...
<!-- rename this one to app/something12345.js -->
<script src="app/something.js"></script>
<!-- leave this one as it is -->
<script src="vendor/angular.js"></script>
...
到目前为止,在我的 pom.xml 中,我对 maven-replacer-plugin 进行了此配置
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.2</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<file>target/${project.build.finalName}/index.html</file>
<replacements>
<replacement>
<token>(\.js")</token>
<value>12345.js"</value>
</replacement>
</replacements>
</configuration>
</plugin>
目前这显然将取代所有
.js
火柴。我可以在
<token>
中加入一些魔法咒语吗?节实现这一目标?
最佳答案
我设法使用以下方法做到了这一点
<replacement>
<token>((app/)(.)*)(\.js")</token>
<value>$112345.js</value>
</replacement>
虽然在我的实际应用中我替换了
12345
与 ${buildNumber}
变量,所以语法是<replacement>
<token>((app/)(.)*)(\.js")</token>
<value>$1${buildNumber}.js</value>
</replacement>
我希望这可能会使解决方案更容易理解
关于regex - 使用 maven-replacer-plugin 选择性替换正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25146073/