26) minify-maven-plugin 合并压缩 js css文件
http://samaxes.github.io/minify-maven-plugin/minify-mojo.html
<build> <plugins> <plugin> <groupId>com.samaxes.maven</groupId> <artifactId>minify-maven-plugin</artifactId> <version>1.7.6</version> <executions> <execution> <id>default-minify</id> <configuration> <charset>UTF-8</charset> <cssSourceFiles> <cssSourceFile>file-1.css</cssSourceFile> <!-- ... --> <cssSourceFile>file-n.css</cssSourceFile> </cssSourceFiles> <jsSourceFiles> <jsSourceFile>file-1.js</jsSourceFile> <!-- ... --> <jsSourceFile>file-n.js</jsSourceFile> </jsSourceFiles> <jsEngine>CLOSURE</jsEngine> </configuration> <goals> <goal>minify</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
实例:
<build> <!-- merge and compress --> <plugins> <plugin> <groupId>com.samaxes.maven</groupId> <artifactId>minify-maven-plugin</artifactId> <version>1.6</version> <executions> <execution> <id>default-minify</id> <phase>process-resources</phase> <configuration> <!-- webapp --> <webappSourceDir>${basedir}/src/main/webapp</webappSourceDir> <webappTargetDir>${basedir}/target/classes</webappTargetDir> <!-- js --> <jsEngine>yui</jsEngine> <jsSourceDir>js</jsSourceDir> <jsTargetDir>runtime</jsTargetDir> <jsFinalFile>core.js</jsFinalFile> <jsSourceIncludes> <jsSourceInclude>a**.js</jsSourceInclude> <jsSourceInclude>b**.js</jsSourceInclude> </jsSourceIncludes> <!-- css --> <cssSourceDir>css</cssSourceDir> <cssTargetDir>runtime</cssTargetDir> <cssFinalFile>core.css</cssFinalFile> <cssSourceIncludes> <cssSourceInclude>a**.css</cssSourceInclude> <cssSourceInclude>b**.css</cssSourceInclude> </cssSourceIncludes> </configuration> <goals> <goal>minify</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
将最终的文件打到jar中
注意:如果是jar 那么webapp中的内容是不过自动包含到jar中
${basedir}/target/classes
上面这个是个特殊目录 是 ${project.build.outputDirectory} ,jar会将这个里面的内容打包
处理图片可以通过 maven-antrun-plugin 复制到 target/classes 下
小技巧:当需要debug调试js时,可以试试把final名字修改为xx.min.js 这样原来的min.js 就是未压缩的了