3

祈祷你能帮助我!

我正在使用SmartSprites将登录页面上的 PNG 合并为一个,以便加载更快。

SmartSprite 将检查您的 CSS 文件,生成 CSS Sprite 图像,并创建一个新的 CSS 文件,该文件将使用此 sprite 图像而不是原始图像。我想要做的是在我的 Maven WAR 构建期间自动将原始 CSS 文件替换为 SmartSprite 文件。

所以这就是我想要发生的事情:

  1. SmartSprite 扫描我的 CSS 文件:mystyle.css
  2. SmartSprite 创建一个精灵图像,并创建一个新的 mystyle-sprite.css文件,该文件引用新的精灵图像。
  3. 我想在构建 WAR 之前将mystyle-sprite.css复制到mystyle.css上,这样我就不必更改 JSP 文件中的任何引用。

这两个文件都位于输出目录(target/myproj/css)中。SmartSprite 中似乎没有任何标志来覆盖原始文件,所以我想它必须进行后处理。

下面是我用于 SmartSprite 的 maven 插件配置。

        <plugin>
            <groupId>org.carrot2.labs</groupId>
            <artifactId>smartsprites-maven-plugin</artifactId>
            <version>1.0</version>
            <executions>
                <execution>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>spritify</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
4

2 回答 2

20

恐怕你找不到比 Maven AntRun 插件更简单或更优雅的东西了:

<build>
  <plugins>
    <plugin>
      <artifactId>maven-antrun-plugin</artifactId>
      <version>1.7</version>
      <executions>
        <execution>
          <phase>prepare-package</phase>
          <configuration>
            <target>
              <copy file="${project.build.directory}/mystyle-sprite.css"
                tofile="${project.build.directory}/mystyle.css" />
            </target>
          </configuration>
          <goals>
            <goal>run</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>
于 2012-04-19T14:59:18.823 回答
2

您可以使用Maven WAR 插件

<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <webResources>
            <resource>
                <directory><!-- Your output directory --></directory>
                <targetPath><!-- The target location of the files below --></targetPath>
                <includes>
                    <include><!-- file pattern --></include>
                    <include><!-- file pattern --></include>
                </includes>
            </resource>
        </webResources>
    </configuration>
</plugin>

您还应该将 SmartSprites 配置为使用不同的输出目录来保留原始 CSS 文件名。尝试output-dir-path使用空css-file-suffix值的选项。

于 2012-04-19T14:49:26.993 回答