使用Maven最小化CSS



我有一个Maven配置文件,我想缩小我所有的javascript和css文件。对于开发,我有compressed.jscompressed.css文件,它们只是注入其他脚本/样式表。我想要的是用实际压缩的文件覆盖这些文件,但只有。js缩小对我有效。

这是我个人资料的一部分:

<plugin>
    <groupId>net.alchim31.maven</groupId>
    <artifactId>yuicompressor-maven-plugin</artifactId>
    <version>1.1</version>
    <executions>
        <execution>
            <goals>
                <goal>compress</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <linebreakpos>999999</linebreakpos>
        <jswarn>false</jswarn>
        <excludes>
            <exclude>**/compressed.js</exclude>
        </excludes>
        <aggregations>
            <aggregation>
                <removeIncluded>true</removeIncluded>
                <insertNewLine>false</insertNewLine>
                <output>${project.build.directory}/${project.build.finalName}/js/compressed.js
                </output>
                <includes>
                    <include>**/components/sample-min.js</include>
                    <include>**/components/sample2-min.js</include>
                </includes>
                <excludes>
                    <exclude>**/compressed.js</exclude>
                </excludes>
            </aggregation>
        </aggregations>
    </configuration>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <excludes>js/**</excludes>
    </configuration>
</plugin>

当我修改以下行时,当已经有compressed.css存在时,它根本不起作用,当不存在时,它会最小化。

添加到yuicompressor-maven-plugin:

<exclude>**/compressed.css</exclude>
...
<aggregations>
    <aggregation>
        <removeIncluded>true</removeIncluded>
        <insertNewLine>false</insertNewLine>
        <output>${project.build.directory}/${project.build.finalName}/css/compressed.css
        </output>
        <includes>
            <include>**/sample-min.css</include>
            <include>**/sample2-min.css</include>
        </includes>
        <excludes>
            <exclude>**/compressed.css</exclude>
        </excludes>
    </aggregation>

maven-war-plugin变化:

<excludes>
    <exclude>js/**</exclude>
    <exclude>css/**</exclude>
</excludes>
请告诉我,我做错了什么?

Yui压缩器用于压缩.js文件是非常老的。我使用yui压缩器。css和谷歌闭包编译器。js文件。代码如下所示。它们会最小化你所有的。css和。js文件,并在项目的构建阶段覆盖它们。

    <!-- css compression -->
        <plugin>
            <groupId>net.alchim31.maven</groupId>
            <artifactId>yuicompressor-maven-plugin</artifactId>
            <version>1.5.1</version>
            <executions>
                <execution>
                    <configuration>
                        <webappDirectory>${project.build.sourceDirectory}srcmainresourcespublicassets</webappDirectory>
                        <nosuffix>true</nosuffix>
                        <force>true</force>
                        <jswarn>false</jswarn>
                        <excludes>
                            <exclude>**/*.min.js</exclude>
                            <exclude>**/*-min.js</exclude>
                            <exclude>**/*.js</exclude>
                        </excludes>
                    </configuration>
                    <goals>
                        <goal>compress</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    <!--JavaScript Compression Part-->
        <plugin>
            <groupId>com.github.blutorange</groupId>
            <artifactId>closure-compiler-maven-plugin</artifactId>
            <version>2.16.0</version>
            <configuration>
                <baseSourceDir>${project.basedir}srcmainresourcespublicassets</baseSourceDir>
                <baseTargetDir>${project.build.directory}classespublicassets</baseTargetDir>
            </configuration>
            <executions>
                <execution>
                    <id>default-minify</id>
                    <configuration>
                        <encoding>UTF-8</encoding>
                        <sourceDir></sourceDir>
                        <outputFilename>#{path}/#{basename}.#{extension}</outputFilename>
                        <targetDir></targetDir>
                        <includes>**/*.js</includes>
                        <excludes>
                            <exclude>**/*.min.js</exclude>
                        </excludes>
                        <skipMerge>true</skipMerge>
                        <closureLanguageOut>ECMASCRIPT5</closureLanguageOut>
                    </configuration>
                    <goals>
                        <goal>minify</goal>
                    </goals>
                    <phase>generate-resources</phase>
                </execution>
            </executions>
        </plugin>

相关内容

  • 没有找到相关文章

最新更新