2010-10-01 38 views
6

Tôi đang sử dụng máy nén yui để nén các tệp js trong ứng dụng web của mình.máy nén yui maven plugin không nén các tệp js

Tôi đã định cấu hình plugin như được nêu trên trang web plugin yui maven yui compressor maven plugin.

Đây là pom Plugin conf

<plugin> 
    <groupId>net.sf.alchim</groupId> 
    <artifactId>yuicompressor-maven-plugin</artifactId> 
    <version>0.7.1</version> 
    <executions> 
     <execution> 
    <phase>compile</phase> 
     <goals> 
     <goal>jslint</goal> 
      <goal>compress</goal> 
     </goals> 
     </execution> 
    </executions>   
    <configuration> 
    <failOnWarning>true</failOnWarning> 
     <nosuffix>true</nosuffix> 
     <force>true</force> 
     <aggregations> 
     <aggregation> 
      <!-- remove files after aggregation (default: false) --> 
      <removeIncluded>false</removeIncluded> 
      <!-- insert new line after each concatenation (default: false) --> 
      <insertNewLine>false</insertNewLine> 
      <output>${project.basedir}/${webcontent.dir}/js/compressedAll.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>**/autocomplete.js</include> 
      <include>**/calendar.js</include> 
      <include>**/dialogs.js</include> 
      <include>**/download.js</include> 
      <include>**/folding.js</include> 
      <include>**/jquery-1.4.2.min.js</include> 
      <include>**/jquery.bgiframe.min.js</include> 
      <include>**/jquery.loadmask.js</include> 
      <include>**/jquery.printelement-1.1.js</include> 
      <include>**/jquery.tablesorter.mod.js</include> 
      <include>**/jquery.tablesorter.pager.js</include> 
      <include>**/jquery.dialogs.plugin.js</include> 
      <include>**/jquery.ui.autocomplete.js</include>     
      <include>**/jquery.validate.js</include> 
      <include>**/jquery-ui-1.8.custom.min.js</include> 
      <include>**/languageDropdown.js</include> 
      <include>**/messages.js</include> 
      <include>**/print.js</include> 
      <include>**/tables.js</include> 
      <include>**/tabs.js</include> 
      <include>**/uwTooltip.js</include> 
      </includes> 
      <!-- files to exclude, path relative to output's directory--> 

     </aggregation> 
     </aggregations> 
    </configuration> 
    <dependencies> 
     <dependency> 
<groupId>rhino</groupId> 
    <artifactId>js</artifactId>  
    <scope>compile</scope> 
    <version>1.6R5</version> 
</dependency> 
<dependency> 
     <groupId>org.apache.maven</groupId> 
     <artifactId>maven-plugin-api</artifactId> 
     <version>2.0.7</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.maven</groupId> 
     <artifactId>maven-project</artifactId> 
     <version>2.0.7</version> 
     <scope>provided</scope> 
    </dependency><dependency> 
     <groupId>net.sf.retrotranslator</groupId> 
     <artifactId>retrotranslator-runtime</artifactId> 
     <version>1.2.9</version> 
     <scope>runtime</scope> 
    </dependency> 

    </dependencies> 
    </plugin> 

Và đây là nhật ký lúc nén

 
These will use the artifact files already in the core ClassRealm instead, to allow them to be included in PluginDescriptor.getArtifacts().

[DEBUG] Configuring mojo 'net.sf.alchim:yuicompressor-maven-plugin:0.7.1:jslint' [DEBUG] (f) failOnWarning = true [DEBUG] (f) jswarn = true [DEBUG] (f) outputDirectory = C:\test\target\classes [DEBUG] (f) project = MavenProject: com.test.test1:test2:19-SNAPSHOT @ C:\test\pom.xml [DEBUG] (f) resources = [Resource {targetPath: null, filtering: false, FileSet {directory: C:\test\src, PatternSet [includes: {}, excludes: {/*.class, **/.java, site/}]}}] [DEBUG] (f) sourceDirectory = C:\test\src..\js [DEBUG] (f) warSourceDirectory = C:\test\src\main\webapp [DEBUG] (f) webappDirectory = C:\test\target\test2-19-SNAPSHOT [DEBUG] -- end configuration -- [INFO] [yuicompressor:jslint {execution: default}] [INFO] nb warnings: 0, nb errors: 0 [DEBUG] Configuring mojo 'net.sf.alchim:yuicompressor-maven-plugin:0.7.1:compress' --> [DEBUG] (f) removeIncluded = false [DEBUG] (f) insertNewLine = false [DEBUG] (f) output = C:\test\WebContent\js\compressedAll.js [DEBUG] (f) includes = [/autocomplete.js, /calendar.js, **/dialogs.js, **/download.js, **/folding.js, **/jquery-1.4.2.min.js, **/jquery.bgifram e.min.js, **/jquery.loadmask.js, **/jquery.printelement-1.1.js, **/jquery.tablesorter.mod.js, **/jquery.tablesorter.pager.js, **/jquery.dialogs.p lugin.js, **/jquery.ui.autocomplete.js, **/jquery.validate.js, **/jquery-ui-1.8.custom.min.js, **/languageDropdown.js, **/messages.js, **/print.js, * */tables.js, **/tabs.js, **/uwTooltip.js] [DEBUG] (f) aggregations = [[email protected]] [DEBUG] (f) disableOptimizations = false [DEBUG] (f) encoding = Cp1252 [DEBUG] (f) failOnWarning = true [DEBUG] (f) force = true [DEBUG] (f) gzip = false [DEBUG] (f) jswarn = true [DEBUG] (f) linebreakpos = 0 [DEBUG] (f) nomunge = false [DEBUG] (f) nosuffix = true [DEBUG] (f) outputDirectory = C:\test\target\classes [DEBUG] (f) preserveAllSemiColons = false [DEBUG] (f) project = MavenProject: com.test.test1:test2:19-SNAPSHOT @ C:\test\pom.xml [DEBUG] (f) resources = [Resource {targetPath: null, filtering: false, FileSet {directory: C:\test\src, PatternSet [includes: {}, excludes: {/.class, /.java, site/}]}}] [DEBUG] (f) sourceDirectory = C:\test\src..\js [DEBUG] (f) statistics = true [DEBUG] (f) suffix = -min [DEBUG] (f) warSourceDirectory = C:\test\src\main\webapp [DEBUG] (f) webappDirectory = C:\test\target\test2-19-SNAPSHOT [DEBUG] -- end configuration -- [INFO] [yuicompressor:compress {execution: default}] [INFO] generate aggregation : C:\test\WebContent\js\compressedAll.js [INFO] compressedAll.js (407505b) [INFO] nb warnings: 0, nb errors: 0 [DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-resources-plugin:2.2:testResources' --> [DEBUG] (f) filters = [] [DEBUG] (f) outputDirectory = C:\test\target\test-classes [DEBUG] (f) project = MavenProject: com.test.test1:test2:19-SNAPSHOT @ C:\test\pom.xml [DEBUG] (f) resources = [Resource {targetPath: null, filtering: false, FileSet {directory: C:\test\test , PatternSet [includes: {}, excludes: {/.class, **/*.java}]}}] [DEBUG] -- end configuration --

Vấn đề là các tập tin đang nhận được tổng hợp thành một tập tin nhưng không nén.

Liên kết ở trên sử dụng phiên bản 1.1 và phiên bản plugin tôi đang sử dụng là 0.7.1. Điều này sẽ làm cho bất kỳ khác biệt.

Ai đó có thể nói điều gì sai ở đây.

PS: Tôi đã làm xáo trộn một số văn bản trong nhật ký tuân theo sự tuân thủ trong công ty của tôi. Vì vậy, bạn có thể thấy nó không khớp ở đâu đó.

+0

Tôi gặp sự cố tương tự. Các tệp "rút gọn" giữ lại tất cả các ngắt dòng của chúng. Mặc dù vậy, công việc ghép nối vẫn hoạt động. Rất lạ ... – Benxamin

Trả lời

0

Bạn có thể thử xác định riêng rẽ thực hiện để lấy và nén và xem liệu điều đó có hiệu quả không?

<executions> 
    <execution> 
     <goals> 
      <goal>jslint</goal>   
     </goals> 
     <configuration> ... </configuration> 
    </execution> 
    <execution> 
     <goals> 
      <goal>compress</goal>   
     </goals> 
     <configuration> ... </configuration> 
    </execution> 
</executions> 
+0

Được thực hiện dưới dạng hai lần thực hiện khác nhau. Nhưng không may mắn vẫn là tình huống tương tự. – hanumant

+0

Xóa mục tiêu jslint khỏi pom và chỉ thực thi nén để xem nó có hoạt động hay không. Kết quả là không, nén không làm việc chỉ tổng hợp. – hanumant

0

Máy nén YUI (bao gồm như là một sự phụ thuộc trong plugin maven này) sử dụng một "vá" phiên bản của Mozilla Rhino:

  • giải thích javascript
  • nén tên biến cục bộ (các "patch")

Bằng cách thêm chính mình sự phụ thuộc vào Rhino (in your previous question), tôi nghĩ những điều này " các bản vá lỗi "bị ghi đè, biến plugin này thành một thứ gì đó vô ích: các hành vi xóa tên, xóa không gian đã biến mất.

Vì vậy, hãy loại bỏ tê giác khỏi pom của bạn và quay lại để giải quyết vấn đề đầu tiên của bạn!

+0

hmm, tôi đã có cùng một vấn đề mà không xác định rõ ràng Rhino – Jan

5

Từ những gì tôi đọc, bạn không định cấu hình địa điểm nơi tệp js phải được kiểm tra hoặc nén (vì bạn không sử dụng cấu hình mặc định). Bạn chỉ định cấu hình tập hợp.

Để được phản hồi nhanh hơn sử dụng issue tracker of yuicompressor-maven-plugin

Giải pháp (copy/paste từ project FAQ)

Bởi vì:

  • bạn thiết <nosuffix>true</nosuffix>

  • kịch bản của bạn ở dưới src/main/webapp và maven-war-plugin sao chép mọi tệp từ src/main/webapp vào mục tiêu ess dấu thời gian, ...) và làm cho cuộc chiến (trong cùng một thực hiện).

Cách giải quyết:

  • di chuyển kịch bản của bạn dir ra từ webapp

    <plugin> 
        <groupId>@[email protected]</groupId> 
        <artifactId>yuicompressor-maven-plugin</artifactId> 
        ... 
        <configuration> 
        <!-- default ${project.build.sourceDirectory}/../js == src/main/js --> 
        <sourceDirectory>src/main/javascript</sourceDirectory> 
    
  • OR loại trừ "kịch bản" từ danh sách các tập tin cần sao chép

    <!-- adapted from https://github.com/davidB/yuicompressor-maven-plugin/blob/master/src/it/demo01/pom.xml --> 
    <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-war-plugin</artifactId> 
        <configuration> 
        <warSourceExcludes>scripts/**</warSourceExcludes> 
        </configuration> 
    </plugin> 
    
2

Tôi biết bài đăng này là rất cũ, nhưng tôi đã xem qua cùng một điều và đây là những gì tôi tìm thấy. Hy vọng rằng điều này sẽ giúp người khác là tốt.

Điều này rất khó. Điều này phải làm với tùy chọn cấu hình nosuffix. Nếu bạn loại bỏ tùy chọn nosuffix, việc rút gọn hoạt động như mong đợi.

Nếu bạn thực sự phải có nosuffix thì bạn cần phải thay đổi giai đoạn thực hiện thành "gói".

<executions> 
     <execution> 
     <phase>package</phase> 
      <goals> 
    ...... 
    ..... 

Bất kỳ giai đoạn trước khi chuẩn bị nguồn tài nguyên không hoạt động bởi vì khi chiến tranh được xây dựng, nó nhặt js từ vị trí nguồn gốc và do đó ghi đè js được rút gọn (được tạo ra trong chuẩn bị nguồn lực-pha) trong thư mục đích.

Việc tối thiểu hoạt động khi bạn xóa nosuffix vì trong giai đoạn gói, tên tệp khác nhau, vì vậy không có ghi đè tệp nào và bạn sẽ thấy cả tệp js được rút gọn và không được rút gọn trong thư mục đích của bạn.

Ít nhất đó là sự hiểu biết của tôi.

+1

Trong trường hợp này bạn đã được rút gọn trong thư mục webapp nhưng không phải trong tệp được tạo .war (kiểm tra nội dung, plugin chiến dịch chạy trước (sao chép + lưu trữ trong một Bạn phải loại trừ tệp khỏi bản sao: xem https://github.com/davidB/yuicompressor-maven-plugin/wiki/FAQ –

+1

bạn đã đúng. Tôi thực sự đã kết thúc việc sửa nó bằng cách thêm trong các plugin yuicompressor và sau đó nói thêm rằng cùng một thư mục như một nguồn lực trong maven-chiến-plugin. ' đúng \t \t sai \t \t $ {project.build.directory}/phút ' – Inxsible

Các vấn đề liên quan