Giter Club home page Giter Club logo

yuicompressor-maven-plugin's Introduction

YUICompressor-maven-plugin

Build Status

Overview

Maven's plugin to compress (minify/obfuscate/aggregate) JavaScript and CSS files using YUI Compressor

Documentation

Full documentation is available under following link: http://davidb.github.com/yuicompressor-maven-plugin/

Summary of the project history can be found in CHANGELOG

Build

  • ./mvnw package : generate jar
  • ./mvnw site : generate the plugin website
  • ./mvnw integration-test : ./mvnw package + run all integration test
  • ./mvnw integration-test -Dinvoker.test=demo01 : run integration test 'demo01' (against all configuration) useful for tuning/debug
  • ./mvnw install : ./mvnw integration-test + publish on local maven repository
  • ./mvnw install -Dmaven.test.skip=true : ./mvnw install` without run of unit test and run of integration test
  • release :
    • gpg --use-agent --armor --detach-sign --output $(mktemp) pom.xml to avoid issue on macosx with gpg signature see [MGPG-59] GPG Plugin: "gpg: signing failed: Inap propriate ioctl for device" - ASF JIRA
    • ./mvnw release:clean && ./mvnw release:prepare && ./mvnw release:perform : to publish on staging repository via plugin
    • ./mvnw release:clean && ./mvnw release:prepare -Darguments="-DskipTests -Dmaven.test.skip=true" && ./mvnw release:perform -Darguments="-DskipTests -Dmaven.test.skip=true" to publish without tests
    • ./mvnw site package source:jar javadoc:jar install:install gpg:sign deploy:deploy changes:announcement-generate -Dmaven.test.skip=true -DperformRelease=true : man ual
    • connect to http://oss.sonatype.org/ close and release the request(about yuicompressor-maven-plugin) in staging repositories
    • browse the updated mvnsite (check version into samples, ...)

Issues

Found a bug? Have an idea? Report it to the issue tracker

Developers

License

This project is available under the Creative Commons GNU LGPL, Version 2.1.

yuicompressor-maven-plugin's People

Contributors

aneesh-joseph avatar davidb avatar evilstreak avatar gregersrygg avatar jkingsbery avatar joshuagoodson-wf avatar linkcaau avatar mshima avatar noctarius avatar pkuczynski avatar rborer avatar tadas-subonis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yuicompressor-maven-plugin's Issues

include/exclude patterns for resources does not work

I have pom.xml defining resources as follows:

    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
            <includes>
                <include>code/**</include>
                <include>html/**</include>
            </includes>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>false</filtering>
            <excludes>
                <exclude>profile/**</exclude>
                <exclude>code/**</exclude>
                <exclude>html/**</exclude>
            </excludes>
        </resource>
        <resource>
            <directory>src/main/resources/profile/${profile.id}</directory>
            <filtering>false</filtering>
        </resource>
    </resources>

Such definition I use because of various resources to be filtered or not and for special resources under src/main/resource/profile/${profile.id} that has to be included only in case that particular profile is active.

Then I use following configuration of the yuicompressor-maven-plugin for compressing just the .js files:

        <plugin>
            <groupId>net.alchim31.maven</groupId>
            <artifactId>yuicompressor-maven-plugin</artifactId>
            <version>1.2</version>
            <executions>
                <execution>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>compress</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <jswarn>false</jswarn>
                <failOnWarning>false</failOnWarning>
                <encoding>UTF-8</encoding>
                <nomunge>false</nomunge>
                <nosuffix>true</nosuffix>
                <excludes>
                    <exclude>profile/**</exclude>
                    <exclude>**/*.css</exclude>
                </excludes>
            </configuration>
        </plugin>

As you see, I have to explicitly exclude the profile/** because without this exclusion the whole tree under src/main/resources/profile is included in the resulting archive. And this is something that I do not want at all.

Moreover all the .js files under src/main/resources are processed exactly 2 times by the yui compressor. I expect this is due to the fact that directory src/main/resources is specified twice in the resources configuration. Some of the are processed 3 times as they reside under the src/main/resources/profile

Currently the pom.xml is working for me, but the repetitive processing of some files is quite unpleasant. Is there some reason why the include/exclude patterns fro resources definition are ignored?

failOnError - switch

Thanks for the plugin.
Would it be possible to add a switch failOnError to allow the plug to continue and not cause a build error on failure to compress a file?

Cannot create resource output directory when searching for nested resources

Whem searching for nested resources (*/.css) a misparse folder can't be created;

[ERROR] Failed to execute goal net.alchim31.maven:yuicompressor-maven-plugin:1.3.0:compress (default) on project freak-core: Cannot create resource output directory: C:${outputDirectory}\C:${file.location} -> [Help 1]

Notice the C:\ in the path.

<plugin>
     <groupId>net.alchim31.maven</groupId>
     <artifactId>yuicompressor-maven-plugin</artifactId>
     <version>1.3.0</version>
     <executions>
         <execution>
             <phase>prepare-package</phase>
             <goals>
                 <goal>compress</goal>
             </goals>
         </execution>
     </executions>
     <configuration>
         <outputDirectory>${project.build.directory}/</outputDirectory>
         <sourceDirectory>${project.build.directory}/</sourceDirectory>
         <nosuffix>true</nosuffix>
         <includes>
             <include>**/*.css</include>
         </includes>
     </configuration>
</plugin>

After using yuicompressor-maven-plugin for minify js/css, the jar under WEB-INF/lib not compressed

After using yuicompressor-maven-plugin for minify js/css, the jar under WEB-INF/lib not compressed

The situation as follow.

Background
There are 43 jar file under WEB-INF/lib in the war file.
The total size (uncompressed) 23512185byte and 21562653byte (compressed)

After adding yuicompressor-maven-plugin in the pom.xml, the build operation succeeded and the js/css files minified.

However, the jar file under WEB-INF/lib is not compressed.
(The whole deployment/war file file size will be increased)

I think it is a minor issue and hope that there will be a solution for such issue.

the default 'linebreakpos' should be -1 not 0.

Since 0 is a special value for 'line-break'

--line-break
Some source control tools don't like files containing lines longer than,
say 8000 characters. The linebreak option is used in that case to split
long lines after a specific column. It can also be used to make the code
more readable, easier to debug (especially with the MS Script Debugger)
Specify 0 to get a line break after each semi-colon in JavaScript, and
after each rule in CSS.

Different configurations for jslint and compress

Hello,

Our web application project which combines 3rd party javascript files with our owns, it seems to me that the current plugin does not allow us to jslint only our files and to compress our files plus some 3rd party libraries.

It would be useful to be able to define a different configuration per goal or maybe there should be 2 plugins.

Thanks,

Gael

IllegalArgumentException: Illegal group reference

I get the following stacktrace when trying to compress my JavaScript files:

java.lang.IllegalArgumentException: Illegal group reference
at java.util.regex.Matcher.appendReplacement(Matcher.java:713)
at com.yahoo.platform.yui.compressor.CssCompressor.compress(CssCompressor.java:86)
at net_alchim31_maven_yuicompressor.YuiCompressorMojo.processFile(YuiCompressorMojo.java:182)
at net_alchim31_maven_yuicompressor.MojoSupport.processDir(MojoSupport.java:162)
at net_alchim31_maven_yuicompressor.MojoSupport.execute(MojoSupport.java:116)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
...
The code base is, unfortunately, proprietary, so I cannot include example code, but I wonder if this isn't the same problem: http://tech.soronthar.com/2007/12/javalangillegalargumentexcepti.html

Can't create folder on aggregate

From the example:

${project.build.directory}/${project.build.finalName}/static/all.js

Results in an error, that the directory "static" doesn't not exists. It would be much better if the plugin could create the directory itself, when it can't found a folder.

compress goal incorrectly processes include resources

Given the following pom.xml:

<project>
    ...
    <build>
        <filters>
            <filter>src/main/filters/dev.properties</filter>
        </filters>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>webapp.properties</include>
                </includes>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>yuicompressor-maven-plugin</artifactId>
                <version>1.1</version>
                <configuration>
                    <nosuffix>true</nosuffix>
                    <jswarn>false</jswarn>
                </configuration>
                <executions>
                    <execution>
                        <id>compress-js-css</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>compress</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    ...
</project>

The yuicompressor-maven-plugin will incorrectly process the webapp.properties file, resulting in an empty file (0 byte length):

$ mvn process-resources
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building yuicompressor-test-webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ yuicompressor-test-webapp ---
[INFO] Deleting C:\Users\Patrick\Workspaces\Helios\yuicompressor-test-webapp\target
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ yuicompressor-test-webapp ---
[INFO] Copying 1 resource
[INFO]
[INFO] --- yuicompressor-maven-plugin:1.1:compress (compress-js-css) @ yuicompressor-test-webapp ---
[INFO] webapp.properties (0b) -> webapp.properties (0b)[100%]
[INFO] prototype.js (163312b) -> prototype.js (94441b)[57%]
[INFO] test.css (1291b) -> test.css (1057b)[81%]
[INFO] total input (164603b) -> output (95498b)[58%]
[INFO] nb warnings: 0, nb errors: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.578s
[INFO] Finished at: Fri Jan 14 15:56:39 CST 2011
[INFO] Final Memory: 15M/254M
[INFO] ------------------------------------------------------------------------

The only workaround is to explicitly exclude *.properties files in the yuicompressor-maven-plugin configuration:

<plugin>
    <groupId>net.alchim31.maven</groupId>
    <artifactId>yuicompressor-maven-plugin</artifactId>
    <version>1.1</version>
    <configuration>
        <nosuffix>true</nosuffix>
        <jswarn>false</jswarn>
        <excludes>
            <exlude>**/*.properties</exlude>
        </excludes>
    </configuration>
    <executions>
        <execution>
            <id>compress-js-css</id>
            <phase>process-resources</phase>
            <goals>
                <goal>compress</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Log js files on console that are added to the aggregated file

Hi,
please create a log message for each file that will be added to the aggreated file (with maven switch -X). At the moment you cannot see the individual files that are added to the aggregated file. the only thing you see is the actual size of the aggregated file. If you want to check which files have been added to the aggreated file, you have to check the content the aggregated file by yourself.
thanks in advance,
Andy

[1.3.0]nosuffix=true not works

When I set <nosuffix>true</nosuffix>
I can see the log showing the compress results.
But all the css and js files are not changed in my target folder and *.war.

Event I set <force>true</force>

Add to aggregation but ignore for compression

Hi,
is it possible to add a file for aggregation but ignore for the compression (because it is already minified?)
For example the jquery js files are already compressed, but i do also want it in the aggregated file.
So is it possible to add a file for aggregation but skip the compression for it?
Thanks,
Andy

Minifying in parallel

It would be nice to have a feature to minify multiple files in parallel. If I have 200 js files to minify in a build, it takes a good several minutes. It should be possible to fork X number of processes to minify different files at the same time, so that the whole build would be done quicker.

Thanks,
Andrey

can't find parent pom

Why is that not in central?

<groupId>net.alchim31.maven</groupId>
<artifactId>alchim31-maven-parent</artifactId>
<version>8</version>

Also, you can remove the oss.sonatype.org-releases from the repositories list, since sonatype syncs that with central.. no need to declare it twice..

Add support for preserving timestamps on compression

Currently there's no support to carry over the timestamp from the input file to the output file.

Below is a patch to achieve this:

diff --git a/src/main/java/net_alchim31_maven_yuicompressor/YuiCompressorMojo.java b/src/main/java/net_alchim31_maven_yuicompressor/YuiCompressorMojo.java
index d62b47a..d97e2fb 100644
--- a/src/main/java/net_alchim31_maven_yuicompressor/YuiCompressorMojo.java
+++ b/src/main/java/net_alchim31_maven_yuicompressor/YuiCompressorMojo.java
@@ -47,8 +47,17 @@ public class YuiCompressorMojo extends MojoSupport {
*
* @parameter expression="${maven.yuicompressor.nosuffix}" default-value="false"
*/
+
private boolean nosuffix;

  • /**

  • \* If maintainTimestamps is true, the timestamps found on the files will be reapplied after compression
    
  • \* 
    
  • \* @parameter expression="${maven.yuicompressor.maintainTimestamps}" default-value="true"
    
  • */
    
  • private boolean maintainTimestamps;

  • /**

    • Insert line breaks in output after the specified column number.
      *
      @@ -172,6 +181,7 @@ public class YuiCompressorMojo extends MojoSupport {
      getLog().debug("compress file :" + src.toFile()+ " to " + src.toDestFile(suffix));
      }
      File inFile = src.toFile();
  •    Long inFileTimestamp = inFile.lastModified();
     File outFile = src.toDestFile(suffix);
    
     getLog().debug("only compress if input file is younger than existing output file");
    

    @@ -212,6 +222,10 @@ public class YuiCompressorMojo extends MojoSupport {
    }
    FileUtils.forceDelete(outFile);
    FileUtils.rename(outFileTmp, outFile);

  •    if (maintainTimestamps)
    
  •    {
    
  •       outFile.setLastModified(inFileTimestamp);
    
  •    }
     File gzipped = gzipIfRequested(outFile);
     if (statistics) {
         inSizeTotal_ += inFile.length();
    

Include & exclude with YUICompressor

Hi David,

I have directory structure as
src/main/webapp/app
src/main/webapp/mod
src/main/webapp/framework

src/main/webapp/content
src/main/webapp/content/ko/
src/main/webapp/export

I want compress of app , mod & framwork folder only . Rest should be copied as it is.
I tried following configuration but It doesn't include excluded folder in my WAR. Can you help me out please

[code ]
executions>
execution>
goals>
goal>compress
/goals>
/execution>
/executions>
configuration>
excludes>
exclude>/content//.
exclude>/export//.
/excludes>
nosuffix>true
jswarn>true
/configuration>

[/code ]

<nomunge> is the wrong way around, false causes no munging

Currently in 1.3.0: When is specified, "false" causes local variables to be preserved (i.e. it is not munging) and "true" causes local variables to be optimised (i.e. it is munging*).

Desired:

  • nomunge=false should mean munge=true should mean "please munge my local variables"
  • nomunge=true should mean munge=false should mean "please leave my local variables alone"

It may be problematic to change the meaning of this parameter in a backward-compatible way.

CSS aggregate: remove @import

some css files might contain reference to other css files i.e: @import "slider.css" screen;
would be nice to have parameter that will remove those lines of code during aggregation.

Define acceptable undeclared variables

When using jslint/compress, it complains that an undeclared variable exists: $ when the js file relies on JQuery, and Ext when the js file relies on ExtJS.

I think jslint supports a way to specify predefined variables. If so, then I'd like to be able to say that '$' and 'Ext' are OK and should not see a warning for those.

mvn clean removes directories Aggregation#run depends on

Running mvn clean deletes the entire target directory. For my project, this plugin is the first thing to run afterwards, so when it tries to open the FileOutputStream, it fails.
There should be an option to create missing directory parents of the output destination.

This is the configuration I'm using:

  <plugin>
    <groupId>net.alchim31.maven</groupId>
    <artifactId>yuicompressor-maven-plugin</artifactId>
    <executions>
      <execution>
        <goals>
          <goal>compress</goal>
        </goals>
      </execution>
    </executions>    
    <configuration>
      <nosuffix>true</nosuffix>
      <aggregations>
        <aggregation>
          <!-- remove files after aggregation (default: false)
          <removeIncluded>true</removeIncluded>
          -->
          <!-- insert new line after each concatenation (default: false)
          <insertNewLine>true</insertNewLine>
          -->

          <!-- output>${project.build.directory}/${project.build.finalName}/scripts/cms.js</output -->
          <output>${project.build.sourceDirectory}/scripts/cms.js</output>

          <!-- files to include, path relative to output's directory or absolute path-->
          <includes>
<include>${project.build.sourceDirectory}/scripts/prototype.js</include>
<include>${project.build.sourceDirectory}/scripts/scriptaculous/scriptaculous.js</include>
<include>${project.build.sourceDirectory}/scripts/utils.js</include>
<include>${project.build.sourceDirectory}/scripts/menu.js</include>
<include>${project.build.sourceDirectory}/scripts/autocomplete.js</include>
<include>${project.build.sourceDirectory}/scripts/tabbedpanes.js</include>
<include>${project.build.sourceDirectory}/scripts/navigation.js</include>
<include>${project.build.sourceDirectory}/scripts/formButton.js</include>
<include>${project.build.sourceDirectory}/scripts/setAllCheckBoxes.js</include>
<include>${project.build.sourceDirectory}/scripts/softFields.js</include>
<include>${project.build.sourceDirectory}/calendar/calendar.js</include>
<include>${project.build.sourceDirectory}/calendar/calendar-setup.js</include>
<include>${project.build.sourceDirectory}/calendar/calendar-en.js</include>
          </includes>

          <!-- files to exclude, path relative to output's directory
          <excludes>
            <exclude>**/*.pack.js</exclude>
            <exclude>**/compressed.css</exclude>
          </excludes>
          -->
        </aggregation>
      </aggregations>
    </configuration>
  </plugin>

Project structure is:
base/WebContent/calendar }
base/WebContent/scripts } These three contain JS files
base/WebContent/scripts/scriptaculous }
base/target/base-version/scripts/all.js - This is where I want my output

This is the error I get when running mvn clean package:

[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] wrap: C:\...\WebContent\scripts\prototype.js (The
 system cannot find the file specified)

This may be a separate issue but - when I tried to workaround this by using the following output:
${project.build.sourceDirectory}/scripts/all.js

Something (presumably this plugin) deleted everything in that folder and produced a 0-byte output. Fortunately I'm running version control.

These three lines inserted in Aggregation#run just above the FileOutputStream creation fix the issue adequately for my purposes:

        if (!output.canWrite()) {
            output.getAbsoluteFile().getParentFile().mkdirs();
        }

Compress Statistics are incorrect

When I run my build, I am seeing messages like:

[INFO] window.css (1487b) -> window.css (1487b)[100%]
[INFO] borders.css (532b) -> borders.css (532b)[100%]
[INFO] box.css (1402b) -> box.css (1402b)[100%]

I know the css is being compressed -- but the original vs. new size are reported the same (and so the ratio is 100%).

need multiple input and output folder

Hi,
i'm working on a project which includes multiple subprojects.
Like this :
input : output:
---xxx/js ---xxx/js
---yyy/js ---yyy/js
---zzz/js ---zzz/js

I need multiple and . I tried using multiple plugin in maven with same groupId and artifactId. It's not working because last plugin overwrites previous plugin definitions. can any one help me?

It's not excluding files correctly.

My plugin definition looks like:

net.alchim31.maven
yuicompressor-maven-plugin
0.9
false



compress



                <nosuffix>true</nosuffix>

                <excludes>
                    <exclude>**/*centroplex.js</exclude>
                    <exclude>**/*iamCore.js</exclude>
                    <exclude>**/*ext-lang*.js</exclude>                     
                    <exclude>**/ext-js</exclude>
                    <exclude>**/ext-ux</exclude>
                    <exclude>**/ext-js/locale</exclude>
                </excludes>
            </configuration>

        </plugin>

However, it's still processing everything in the ext-js/locale directory anyway. The directory path is: ${builddir}/webapp/js/ext-js/locale

includes/excludes patterns work only for resources not for webapp

Bonjour David,

Thanks for this very useful plugin.

I spent some time trying to figure how the includes/excludes work until I had a look at the MojoSuppport.execute() method.
In this code, I saw that the includes/excludes patterns are taken into account only for resources not for for the webapp directory itself.

I was looking at this feature to prevent YUI compressor to process Ext JS library files as they are already minified, have some warnings and it takes some time to process them.

So am I right that the only solution for me is to create a new maven module to isolate my javascript files from 3rd party javascript files?

Thanks,

Gaël

Example about include only a few files and aggretate it into one file

Hello,

I don't where to post it, and I post it to an issue.

I've several js files and I only need to compress and aggregate a few ones into a directory. What I've to do it?

I need to do something like this:

directory1

  • file1.js
  • file2.js
    directory2
    • file3.js
      directoryn
      -filen.js

I only need to compress and aggregate in a single file directory1

Lot of thanks,

Marcial

Add a copyright header comment to an aggregation

Hello,

When aggregating minified js files, the copyright headers have been stripped out which is fine because we don't want to repeat it several times in the output file.
However it would be great to be able to insert one at beginning of output file.

For simple cases, the maven-license-plugin is enough if you use the same header for all files but it is not enough if you want to have a different header per aggregation (different libraries with different licensing schemes).

Thanks,
Gaël

External config file?

First, THANK YOU for providing this great tool.

Is there any way to put the configuration settings in an external file instead of directly in the pom.xml? Specifically, I'm hoping that I can put the in an external file.

I've tried using the properties-maven-plugin to replace something like ${includes} with info from a .properties file, but that doesn't seem to work.

Is there another mechanism I could use to externalize some/all of the settings, or perhaps a clever way of using a .properties file?

Thanks!

Aggregating files coming from WAR overlay

I'm trying to use the plugin to aggregate CSS files coming from different WAR modules, which are joined in a single WAR file by the Maven WAR plugin (WAR overlay). This process occurs during the war:war goal, which binds to the package phase. The problem I'm facing is that there is no single directory containing all my CSS files before the package phase. Only during the package phase is the target directory created, containing all the CSS files I have. However, when the package phase ends, it is already too late to invoke the plugin, since the final WAR has already been built. Is there a way to configure the plugin to work in projects that use WAR overlays?

A "skip" configuration property

I'd like to conditionally disable the execution of this plugin using a configuration property (like the javadoc plugin's skip property: http://maven.apache.org/plugins/maven-javadoc-plugin/javadoc-mojo.html#skip).

Something like this could be added to MojoSupport (sorry I'm too lazy to make a real patch):

/**
 * Whether to skip execution.
 *
 * @parameter expression="${maven.yuicompressor.skip}" default-value="false"
 */
private boolean skip;

// ...

public void execute() throws MojoExecutionException, MojoFailureException {
    try {
        if (skip) {
            return;
        }
        // ...

I might be able to accomplish the same thing using profiles, but this kind of thing would make my pom simplest.

-Jesse

removeIncluded shouldn't remove outside from target dircetory

There is no "guard" against removing file from src, or to only remove file under target, when using , it's a bug.
So When removeIncluded is "true" and aggregation's includes contains file from src (copyright, ...) then the source file is removed.

yui compressor maven plugin doesnt compress the js files using phonegap

Hi, my js files get aggregated in one, but not compressed. I think it's because I'm using phonegap to develop mobile apps, but I have not seen any conflicts. This is my pom.xml:

        <plugin>
            <groupId>net.alchim31.maven</groupId>
            <artifactId>yuicompressor-maven-plugin</artifactId>
            <version>1.2</version>
            <executions>
                <execution>
                   <phase>process-resources</phase>
                    <goals>
                        <goal>compress</goal>
                    </goals>
                </execution>
            </executions>        
            <configuration>
                <preProcessAggregates>true</preProcessAggregates>
                <failOnWarning>true</failOnWarning>
                <aggregations>
                    <aggregation>
          <!-- remove files after aggregation (default: false)
          <removeIncluded>true</removeIncluded>
          -->
          <!-- insert new line after each concatenation (default: false) -->
                        <insertNewLine>true</insertNewLine>
                        <output>${basedir}/assets/www/js/test-all.js</output>
          <!-- files to include, path relative to output's directory or absolute path-->
          <!--inputDir>base directory for non absolute includes, default to parent dir of output</inputDir-->
                        <includes>
                            <include>**/*.js</include>
                        </includes>        
                    </aggregation>
                </aggregations>
            </configuration>
        </plugin>

aggregating CSS which contains relative reference

I am aggregating several CSS files. The output file is created in an other directory than the aggregated files. If the aggregated files refers an other file, e.g. an image like this
background: url(../images/bg-searchbx.png) 0 0 no-repeat;
than this reference is not valid anymore.

The aggregator should be aware of this and adapt the reference.

Skip parameter not honored

I've created a basic maven sample app with the following POM addition:



net.sf.alchim
yuicompressor-maven-plugin
0.7.1



compress




true



Neither the "skip" property in the configuration nor invoking with:
mvn -Dmaven.yuicompressor.skip=true compile
will stop the execution of the plugin.

Aggregate Minification retains linebreaks

When I run the plugin, the resulting minified files (prior to concatenation) have CSS rules compressed down to one line for each rule. The JS files have no extra whitespace (no indentation, no double-spaced lines). Yet they retain one line for each line of code. The resulting files contain hundreds of lines, instead of just one.

After the aggregation, the files do not are still not fully compressed. They retain all the line breaks.
The only setting I found that affects line breaks is the configuration setting. And it only works on aggregated files.

When you set that value to an arbitrarily high number (999999), then it will allow the aggregated files to consist of just one line. It does not operate on the "minified" files before aggregation.

It would be better to have another variable that toggles this line breaks feature.
I can see the value of getting this plugin running–and not fully minifying the code–in a development environment. However, it's not what we require for production, and it's not what we expect when using YUI Compressor.

I prefer to have the line breaks stripped with the rest of the white space. And it would be nice to see this operate on each file, prior to aggregation.

true

Here are the working setting from my pom.xml:

        <!-- 

                YUI Compressor 

        -->
        <plugin>
            <groupId>net.alchim31.maven</groupId>
            <artifactId>yuicompressor-maven-plugin</artifactId>
            <version>1.1</version>
            <executions>
                <execution>
                    <!-- YUI Compressor has two goals: compress and jslint -->
                    <goals>
                        <goal>compress</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <!-- Great for debugging -->
                <failOnWarning>true</failOnWarning>
                <!-- Force compress of every file, regardless of presence or age. -->
                <force>true</force>
                <!-- Break contiguous output at this column number. -->
                <!-- If this is zero, you will get line breaks after every line in the aggregated file. -->
                <linebreakpos>999999</linebreakpos>
                <!-- Set your own suffix. [default: "-min"]-->
                <suffix>.min</suffix>
                <aggregations>
                    <!--   
                            JavaScript concatenation
                    -->
                    <aggregation>
                        <!-- Insert a new line after each concatenation. -->
                        <insertNewLine>false</insertNewLine>
                        <!-- Pathname of final output. -->
                        <output>${project.build.directory}/${project.build.finalName}/resources/js/global.min.js</output>
                        <!-- Files to include, path relative to output directory OR absolute path -->
                        <includes>
                            <inlcude>../html5/canvasDefault.min.js</inlcude>
                        </includes>
                    </aggregation>
                    <!-- 
                            CSS concatenation
                    -->
                    <aggregation>
                        <!-- Pathname of final output. -->
                        <output>${project.build.directory}/${project.build.finalName}/resources/stylesheet/base.min.css</output>
                        <!-- Files to include, path relative to output directory OR absolute path -->
                        <includes>
                            <include>../css/demo_template.min.css</include>
                            <include>../css/override_header.min.css</include>
                            <include>../css/override_styles.min.css</include>
                            <include>../css/screen.min.css</include>
                            <include>../css/showcase_styles.min.css</include>
                        </includes>
                    </aggregation>
                </aggregations>
            </configuration>
        </plugin>

Setting property <nosuffix> to true causes the plugin to always compress files that have not changed

Hi,

Because we want to keep the name of the js files the same before and after compression, we have set the nosuffix flag to true. However, this causes the plugin to run through the list and recompress files every time even though they have not changed. I find that if I made this one line change in net.sf.alchim.mojo.yuicompressor.MojoSupport.java to set destAsSource to false, then the plugin works as needed. The line of code is in execute():

from:
processDir(sourceDirectory, outputDirectory, null, null, true);

to:
processDir(sourceDirectory, outputDirectory, null, null, false);

I'm not sure if this is the optimal solution but can you either apply this patch or fix this issue? Thanks.

Ngan

Folder structures in aggregate/exclude

Congratulations for this tool, simple and effective. Is there any way to use exclusions for specific directories, not just JS files. Wildcards on directories don't work properly.
It's possible to update documentation with all compress options? Not reflected in current documentation.

Provide ChangeLog.txt

Hi,

can you start providing ChangeLog to this project, so its easier to follow changes? :)

Regards

Piotr

Media Query Minification Breaks

During compression of CSS files, the version of yui compressor being used in this plugin breaks media queries (it removes the space after "and", which is required). This is fixed in the newer versions of yui compressor. Is there a chance that the version of yui compressor can be updated for this plugin?

Thanks!

YUI compressor throws error on utf-8 encoded file.

The YUI compressor is throwing an error on a utf-8 encoded file. It works on a windows box, but not a linux box.
There is an option --charset that can be used to set the encoding, but I see no way to set that via maven. Could this be added?

Option to exclude resources folder

Please add an option to ignore the src/main/resources folder. This seems to be only useful for Wicket applications.

The main problem is, that the exclude pattern doesn't work to te exclude the complete resources folder:
src/main/resources
/resources//*
etc.

Or am I just misconfiguring the plugin? Thanks.

Add Eclipse m2e integration

An m2e extension could allow Eclipse Maven projects to pick up on individual changes to resources that need to be re-compressed. As it stands an appropriate Maven phase or goal has to be run manually (either through Eclipse, or on the command line). Then if you're using say WTP hot deployment a refresh of the outputDirectory is required before the change is deployed to your running server.

Extension development is documented here: http://wiki.eclipse.org/M2E_Extension_Development.

For reference here are some other plugins that have implemented m2e extensions:

JiBX:

Axis:

LESSCSS (>= m2e 1.1/Eclipse Juno only):

Typo in jswarn javadoc

Very minor thing, in MojoSupport.java at line 76 the name of the property is jswar__m__ I usppose you meant jswar__n__.

 * @parameter expression="${maven.yuicompressor.jswarm}" default-value="true"
 */
protected boolean jswarn;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.