Maven Javascript Compressor

喜欢而已 提交于 2019-12-18 21:19:10

问题


I want to know how one can compress javascriptfiles using maven. I have lready visited webistes like http://mojohaus.org/javascript-maven-tools/guide-webapp-development.html but there is no implementation explained.

I want to know the dependency for executing the maven plugin.


回答1:


I suggest using the YUI Compressor Maven Mojo and its yuicompressor:compress goal instead. It is well documented, it just works.

To use it, add the following pluginRepository:

  <pluginRepositories>
    <pluginRepository>
      <name>oss.sonatype.org - github-releases</name>
      <id>oss.sonatype.org-github-releases</id>
      <url>http://oss.sonatype.org/content/repositories/github-releases</url>
    </pluginRepository>
  </pluginRepositories>

And declare the plugin:

<project>
  ...
  <build>
    <!-- To define the plugin version in your parent POM -->
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>net.alchim31.maven</groupId>
          <artifactId>yuicompressor-maven-plugin</artifactId>
          <version>0.9</version>
        </plugin>
        ...
      </plugins>
    </pluginManagement>
    <!-- To use the plugin goals in your POM or parent POM -->
    <plugins>
      <plugin>
        <groupId>net.alchim31.maven</groupId>
        <artifactId>yuicompressor-maven-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>compress</goal>
            </goals>
          </execution>
        </executions>   
      </plugin>
      ...
    </plugins>
  </build>
  ...
</project>

Refer to the Usage page and the parameters of yuicompressor:compress for precise configuration.




回答2:


The best and the most advanced one I found till today is wro4j. The idea for the library and the Maven plugin is different from everything I was able to find on the internet, combining pretty much every tool available into one standalone library. Amazing.

You have two modes with wro4j available - first is to operate dynamically as a filter in Java application, second is to use build-time solution with Maven plugin. It's all really straightforward and well explained on the project documentation section, so take a look and dive deep. There are fully operational and well explained examples on how to integrate wro4j with one's application or with Maven build process.




回答3:


You can look at cactus maven plugin



来源:https://stackoverflow.com/questions/3586455/maven-javascript-compressor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!