捆绑和缩小在 maven Web 项目中不起作用



我正在我的示例项目中尝试使用这个插件(以优化性能(,将所有CSS捆绑到一个CSS中,并将所有JS捆绑到一个具有缩小版本的JS中,但是在清理和构建后项目结构保持不变。一切都没有按照预期改变。

我也在 Github 中提出了类似的票证,但没有收到任何更新。

请找到我的项目结构:

├── pom.xml
└── src
├── main
│   ├── java
│   │   └── com
│   │       └── darshan
│   │           └── SourceMapFilter.java
│   ├── resources
│   │   ├── readme.txt
│   │   └── static-bundles.json
│   └── webapp
│       ├── css
│       │   ├── custom.css
│       │   └── style.css
│       ├── index.html
│       ├── js
│       │   ├── custom.js
│       │   └── script.js
│       ├── META-INF
│       │   └── context.xml
│       └── WEB-INF
│           └── web.xml
└── test
└── java

static-bundles.json :

{
"bundles": [
{
"type": "css",
"name": "static-combined.css",
"files": [
"custom.css",
"style.css"
]
},
{
"type": "js",
"name": "static-combined.js",
"files": [
"custom.js",
"script.js"
]
}
]
}

POM.xml插件配置:

<plugin>
<groupId>com.samaxes.maven</groupId>
<artifactId>minify-maven-plugin</artifactId>
<version>1.7.6</version>
<executions>
<execution>
<id>bundle-minify</id>
<phase>package</phase>
<goals>
<goal>minify</goal>
</goals>
<configuration>
<webappSourceDir>${project.basedir}</webappSourceDir>
<webappTargetDir>${project.basedir}</webappTargetDir>
<cssSourceDir>css</cssSourceDir>
<cssSourceFiles>
<cssSourceFile>custom.css</cssSourceFile>
<cssSourceFile>style.css</cssSourceFile>
</cssSourceFiles>
<cssTargetDir>css</cssTargetDir>
<cssFinalFile>static-combined.css</cssFinalFile>
<cssSourceDir>js</cssSourceDir>
<jsSourceFiles>
<jsSourceFile>custom.js</jsSourceFile>
<jsSourceFile>script.js</jsSourceFile>
</jsSourceFiles>
<jsTargetDir>js</jsTargetDir>
<jsFinalFile>static-combined.js</jsFinalFile>
</configuration>
</execution>
</executions>
</plugin>

我已经尝试过绝对路径,但也没有运气。使用 JDK 1.8。

我正在分享替代插件,这解决了我的目的,因为以前的插件(请参阅问题(既不适合我,也没有收到这里和 github 上的任何更新。

在您的pom.xml中添加以下插件。

<plugin>
<groupId>com.github.kospiotr</groupId>
<artifactId>bundler-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>js</id>
<goals>
<goal>process</goal>
</goals>
<configuration>
<verbose>true</verbose>
<munge>false</munge>
<inputFilePah>${project.basedir}/src/main/webapp/index-dev.html</inputFilePah>
<outputFilePath>${project.build.directory}/${project.build.finalName}/index.html</outputFilePath>
</configuration>
</execution>
</executions>
</plugin>

请注意,不需要索引.html。它将自动生成。

索引开发.html:(请注意,捆绑评论是强制性的(

<!-- bundle:css app-#hash#.min.css-->
<link href="css/style.css" rel="stylesheet" type="text/css"/>
<link href="css/custom.css" rel="stylesheet" type="text/css"/>
<!-- /bundle -->
<!-- bundle:js app-#hash#.min.js-->
<script src="js/custom.js"></script>
<script src="js/script.js"></script>
<!-- /bundle -->

生成的索引.html

<link rel="stylesheet" href="app-d3c9aea5a76e300e113c07b3717683b3.min.css"/>
<script src="app-f1b7efa7214d328d11623c0f4b3efb19.min.js"></script>

输出结构

.
├── app-d3c9aea5a76e300e113c07b3717683b3.min.css
├── app-f1b7efa7214d328d11623c0f4b3efb19.min.js
├── css
│   ├── custom.css
│   └── style.css
├── index-dev.html
├── index.html
├── js
│   ├── app.js
│   ├── custom.js
│   └── script.js
├── META-INF
│   └── context.xml
└── WEB-INF
├── classes
│   ├── com
│   │   └── darshan
│   │       └── SourceMapFilter.class
│   ├── readme.txt
│   └── static-bundles.json
└── web.xml

我的工作 github 项目 : https://github.com/darsh9292/bundle-web-app

如果有人仍然对我以前的插件有问题的解决方案,请发布您的答案。

最新更新