简体   繁体   English

捆绑和缩小在 Maven 网络项目中不起作用

[英]Bundle & Minify not working in maven web project

I am trying this plugin (to optimize performance) in my sample project to bundle all the CSS into one CSS, and all the JS into one JS with minified version, but project structure remains same after clean & build.我正在我的示例项目中尝试使用这个插件(以优化性能),将所有 CSS 捆绑到一个 CSS 中,并将所有 JS 捆绑到一个具有缩小版本的 JS 中,但在清理和构建后项目结构保持不变。 Nothing is changing as per expectation.一切都没有按照预期改变。

I have also raised similar ticket in Github , but did not receive any update.我也在Github 上提出了类似的票,但没有收到任何更新。

Please find my project structure :请找到我的项目结构:

├── 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.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 configuration : 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>

I have tried it with absolute path, but no luck with that as well.我已经用绝对路径尝试过,但也没有运气。 Using JDK 1.8.使用 JDK 1.8。

I am sharing alternative plugin, which solves my purpose, since previous plugin (see question) is neither working for me, nor receiving any update on both here as well as on github.我正在共享替代插件,这解决了我的目的,因为以前的插件(请参阅问题)既不适合我,也不在此处和 github 上收到任何更新。

Add below plugin in your pom.xml .在您的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>

Kindly note, no need of index.html.请注意,不需要 index.html。 It will be generated automatically.它将自动生成。

index-dev.html : (Kindly note, bundle comment is mandatory) index-dev.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 -->

Generated index.html :生成的 index.html

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

Output structure :输出结构

.
├── 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

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

If anyone, still has solution with my previous plugin as mentioned in question, please post your answer.如果有人仍然有我之前提到的插件的解决方案,请发布您的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM