在primefaces中缩小js和css文件

时间:2014-04-02 19:18:24

标签: javascript css maven primefaces yui-compressor

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

combine and compress

我可以使用yuicompressor.jar吗? 任何建议都将受到高度赞赏。

1 个答案:

答案 0 :(得分:0)

我使用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

希望这有帮助