猿问

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

我正在我的示例项目中尝试使用这个插件(以优化性能),将所有 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

静态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>


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


GCT1015
浏览 125回答 1
1回答

慕桂英3389331

我正在共享替代插件,这解决了我的目的,因为以前的插件(请参阅问题)既不适合我,也不在此处和 github 上收到任何更新。在您的pom.xml.<plugin>&nbsp; &nbsp; <groupId>com.github.kospiotr</groupId>&nbsp; &nbsp; <artifactId>bundler-maven-plugin</artifactId>&nbsp; &nbsp; <version>1.8</version>&nbsp; &nbsp; <executions>&nbsp; &nbsp; &nbsp; &nbsp; <execution>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <id>js</id>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <goals>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <goal>process</goal>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </goals>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <configuration>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <verbose>true</verbose>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <munge>false</munge>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <inputFilePah>${project.basedir}/src/main/webapp/index-dev.html</inputFilePah>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <outputFilePath>${project.build.directory}/${project.build.finalName}/index.html</outputFilePath>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </configuration>&nbsp; &nbsp; &nbsp; &nbsp; </execution>&nbsp; &nbsp; </executions></plugin>请注意,不需要 index.html。它将自动生成。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 -->生成的 index.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│&nbsp; &nbsp;├── custom.css│&nbsp; &nbsp;└── style.css├── index-dev.html├── index.html├── js│&nbsp; &nbsp;├── app.js│&nbsp; &nbsp;├── custom.js│&nbsp; &nbsp;└── script.js├── META-INF│&nbsp; &nbsp;└── context.xml└── WEB-INF&nbsp; &nbsp; ├── classes&nbsp; &nbsp; │&nbsp; &nbsp;├── com&nbsp; &nbsp; │&nbsp; &nbsp;│&nbsp; &nbsp;└── darshan&nbsp; &nbsp; │&nbsp; &nbsp;│&nbsp; &nbsp; &nbsp; &nbsp;└── SourceMapFilter.class&nbsp; &nbsp; │&nbsp; &nbsp;├── readme.txt&nbsp; &nbsp; │&nbsp; &nbsp;└── static-bundles.json&nbsp; &nbsp; └── web.xml我的工作 github 项目:https : //github.com/darsh9292/bundle-web-app如果有人仍然有我之前提到的插件的解决方案,请发布您的答案。
随时随地看视频慕课网APP

相关分类

Java
我要回答