繁体   English   中英

精简Primefaces中的js和CSS文件

[英]Minifying js and css files in primefaces

我想缩小我的js和CSS文件。 下面的链接显示了组合和压缩js和css文件的方法。 但是,我不想合并文件。

合并并压缩

我可以使用yuicompressor.jar吗? 任何建议将不胜感激。

我使用YUI Compressor Maven Mojo

pom.xml中的这些设置将在流程资源阶段压缩JS和CSS,并将文件名保持原样,并且不添加后缀。

pom.xml

 <pluginRepositories>
    <pluginRepository>
        <name>oss.sonatype.org</name>
        <id>oss.sonatype.org</id>
        <url>http://oss.sonatype.org/content/groups/public</url>
    </pluginRepository>
 </pluginRepositories>
 <build>
    <finalName>${project.artifactId}</finalName>
    <plugins>
        <plugin>
            <groupId>net.alchim31.maven</groupId>
            <artifactId>yuicompressor-maven-plugin</artifactId>
        </plugin>
                    <!-- You should have this already in your pom.xml! -->
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>${version.war.plugin}</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
                <warSourceDirectory>${basedir}/src/main/webapp</warSourceDirectory>
                <encoding>UTF-8</encoding>
                <webResources>
                    <resource>
                        <directory>${project.build.directory}/min</directory>
                    </resource>
                </webResources>
            </configuration>
        </plugin>
    </plugins>
    <pluginManagement>
        <plugins>
            <!-- Javascript and CSS files compression -->
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>yuicompressor-maven-plugin</artifactId>
                <version>1.1</version>
                <configuration>
                <!-- Replace the files (nosuffix needed like ".min" -->
                    <nosuffix>true</nosuffix>
                    <jswarn>false</jswarn>
                    <!-- Overwrite existing files -->
                    <excludes>
                        <exclude>**/*.min.js</exclude>                   
                    <!--<exclude>**/*.css</exclude> *if you want to exclude css*-->
                    </excludes>
                    <warSourceDirectory>${basedir}/src/main/webapp</warSourceDirectory>
                    <webappDirectory>${project.build.directory}/min</webappDirectory>
                    <!-- a new line is added after 1000 columns is reached -->
                    <linebreakpos>1000</linebreakpos>
                </configuration>
                <executions>
                    <execution>
                        <id>compress_js_css</id>
                    <!-- this phase is very important, otherwise the files will be overwritten by the original ones  -->
                        <phase>process-resources</phase>
                        <goals>
                            <goal>compress</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

别忘了您需要做mvn package

希望这可以帮助

暂无
暂无

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

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