至于为什么要用YUI Compressor Maven 插件对js,css 进行压缩,这个相信大家都已经懂了,在这就不多说了
直接上干货
项目结构如下:
pom.xml 如下
<properties> <dui.devMode>false</dui.devMode> <dui.suffix>.min</dui.suffix> </properties> <build> <finalName>Web</finalName> <plugins> <plugin> <!-- YUI Compressor Maven压缩插件 --> <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> <skip>${dui.devMode}</skip> <encoding>UTF-8</encoding> <jswarn>false</jswarn> <force>false</force> <suffix>${dui.suffix}</suffix> <excludes> <exclude>**/*.min.js</exclude> <exclude>**/*.min.css</exclude> </excludes> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.4</version> <configuration> <warSourceExcludes>**/*.js,**/*.css</warSourceExcludes> </configuration> </plugin> </plugins> </build>
控制台运行mvn install
[INFO] --- yuicompressor-maven-plugin:1.3.0:compress (default) @ Web --- [INFO] about.css (1659b) -> about-min.css (1268b)[76%] [INFO] autocomplete.css (524b) -> autocomplete-min.css (407b)[77%] [INFO] control.css (573b) -> control-min.css (417b)[72%] [INFO] detail.css (3048b) -> detail-min.css (2458b)[80%] [INFO] error.css (91b) -> error-min.css (67b)[73%] [INFO] font-awesome.min.css (20766b) -> font-awesome.min-min.css (21232b)[102%] [INFO] hire.css (1159b) -> hire-min.css (854b)[73%] [INFO] index.css (3843b) -> index-min.css (2952b)[76%] [INFO] list.css (3443b) -> list-min.css (2445b)[71%] [INFO] main.css (4042b) -> main-min.css (3051b)[75%] [INFO] common.js (1509b) -> common-min.js (639b)[42%] [INFO] config.js (1322b) -> config-min.js (856b)[64%] [INFO] control.js (1280b) -> control-min.js (791b)[61%] [INFO] detail.js (2244b) -> detail-min.js (1652b)[73%] [INFO] deyou-autocomplete.js (4101b) -> deyou-autocomplete-min.js (2436b)[59%] [INFO] deyou-baiduMapDetail.js (1271b) -> deyou-baiduMapDetail-min.js (603b)[47%] [INFO] hire.js (908b) -> hire-min.js (655b)[72%] [INFO] index.js (1535b) -> index-min.js (815b)[53%] [INFO] list.js (7346b) -> list-min.js (4591b)[62%] [INFO] localization.js (172b) -> localization-min.js (120b)[69%] [INFO] main.js (593b) -> main-min.js (402b)[67%] [INFO] util.js (511b) -> util-min.js (300b)[58%] [INFO] bootstrap-theme.css (14716b) -> bootstrap-theme-min.css (13184b)[89%] [INFO] bootstrap-theme.min.css (13135b) -> bootstrap-theme.min-min.css (13184b)[100%] [INFO] bootstrap.css (121462b) -> bootstrap-min.css (101043b)[83%] [INFO] bootstrap.min.css (102387b) -> bootstrap.min-min.css (100983b)[98%] [INFO] bootstrap.js (58300b) -> bootstrap-min.js (29221b)[50%] [INFO] bootstrap.min.js (27957b) -> bootstrap.min-min.js (28264b)[101%] [INFO] affix.js (3861b) -> affix-min.js (1786b)[46%] [INFO] alert.js (2582b) -> alert-min.js (932b)[36%] [INFO] button.js (3265b) -> button-min.js (1388b)[42%] [INFO] carousel.js (6493b) -> carousel-min.js (3712b)[57%] [INFO] collapse.js (5228b) -> collapse-min.js (2786b)[53%] [INFO] dropdown.js (4477b) -> dropdown-min.js (2051b)[45%] [INFO] modal.js (6975b) -> modal-min.js (4054b)[58%] [INFO] popover.js (3488b) -> popover-min.js (1624b)[46%] [INFO] scrollspy.js (4635b) -> scrollspy-min.js (2212b)[47%] [INFO] tab.js (3413b) -> tab-min.js (1433b)[41%] [INFO] tooltip.js (11908b) -> tooltip-min.js (6684b)[56%] [INFO] transition.js (1964b) -> transition-min.js (548b)[27%] [INFO] galleria.js (213535b) -> galleria-min.js (76481b)[35%] [INFO] galleria.flickr.js (10393b) -> galleria.flickr-min.js (3606b)[34%] [INFO] galleria.history.js (2964b) -> galleria.history-min.js (1086b)[36%] [INFO] galleria.picasa.js (8290b) -> galleria.picasa-min.js (3127b)[37%] [INFO] galleria.classic.css (4780b) -> galleria.classic-min.css (3727b)[77%] [INFO] galleria.classic.js (3011b) -> galleria.classic-min.js (1610b)[53%] [INFO] jquery.js (282766b) -> jquery-min.js (110101b)[38%] [INFO] jquery.min.js (95821b) -> jquery.min-min.js (97699b)[101%] [INFO] jquery.lazyload.js (9056b) -> jquery.lazyload-min.js (3523b)[38%] [INFO] jquery.lazyload.min.js (3381b) -> jquery.lazyload.min-min.js (3438b)[101%] [INFO] jquery.scrollstop.js (2168b) -> jquery.scrollstop-min.js (761b)[35%] [INFO] jquery.scrollstop.min.js (796b) -> jquery.scrollstop.min-min.js (810b)[101%] [INFO] jquery.tmpl.js (19093b) -> jquery.tmpl-min.js (6332b)[33%] [INFO] jquery.tmpl.min.js (6121b) -> jquery.tmpl.min-min.js (6031b)[98%] [INFO] jquery.nouislider.css (2984b) -> jquery.nouislider-min.css (2195b)[73%] [INFO] jquery.nouislider.js (31897b) -> jquery.nouislider-min.js (11013b)[34%] [INFO] jquery.nouislider.min.css (2065b) -> jquery.nouislider.min-min.css (1875b)[90%] [INFO] jquery.nouislider.min.js (12913b) -> jquery.nouislider.min-min.js (13278b)[102%] [INFO] Link.js (9932b) -> Link-min.js (3994b)[40%] [INFO] css-builder.js (5409b) -> css-builder-min.js (3020b)[55%] [INFO] css.js (4011b) -> css-min.js (1516b)[37%] [INFO] css.min.js (1737b) -> css.min-min.js (1315b)[75%] [INFO] normalize.js (4157b) -> normalize-min.js (1301b)[31%] [INFO] require.js (82718b) -> require-min.js (25354b)[30%] [INFO] text.js (15611b) -> text-min.js (4583b)[29%] [INFO] spin.js (10026b) -> spin-min.js (4417b)[44%] [INFO] total input (1303821b) -> output (756293b)[58%] [INFO] nb warnings: 0, nb errors: 0 [INFO] [INFO] --- maven-war-plugin:2.4:war (default-war) @ Web --- [INFO] Packaging webapp [INFO] Assembling webapp [Web] in [/Users/Jerry/work/IdeaProjects/branch/prjDyOnline/Web/target/Web] [INFO] Processing war project [INFO] Copying webapp resources [/Users/Jerry/work/IdeaProjects/branch/prjDyOnline/Web/src/main/webapp] [INFO] Webapp assembled in [301 msecs] [INFO] Building war: /Users/Jerry/work/IdeaProjects/branch/prjDyOnline/Web/target/Web.war [INFO] [INFO] --- maven-install-plugin:2.4:install (default-install) @ Web --- [INFO] Installing /Users/Jerry/work/IdeaProjects/branch/prjDyOnline/Web/target/Web.war to /Users/Jerry/.m2/repository/prjDyOnline/Web/1.0-SNAPSHOT/Web-1.0-SNAPSHOT.war [INFO] Installing /Users/Jerry/work/IdeaProjects/branch/prjDyOnline/Web/pom.xml to /Users/Jerry/.m2/repository/prjDyOnline/Web/1.0-SNAPSHOT/Web-1.0-SNAPSHOT.pom [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 12.811s [INFO] Finished at: Thu Jul 03 10:47:34 CST 2014 [INFO] Final Memory: 35M/700M [INFO] -------------------------
执行成功后,文件结构效果如下:
over 忘拍砖