Gradle
[build.gradle]
dependencies { compile 'com.yahoo.platform.yui:yuicompressor:2.4.8' } apply plugin: 'js' apply plugin: 'css' buildscript { repositories { jcenter() } dependencies { classpath 'com.eriwen:gradle-js-plugin:1.12.1' classpath 'com.eriwen:gradle-css-plugin:1.11.1' } } javascript.source { def targetDir = "$project.projectDir" + File.separatorChar + "webapp" + File.separatorChar + "resources" + File.separatorChar + "js" dev { js { srcDir targetDir include "**/*.js" exclude "**/*.min.js" } } } css.source { def targetDir = "$project.projectDir" + File.separatorChar + "webapp" + File.separatorChar + "resources" + File.separatorChar + "css" dev { css { srcDir targetDir include "**/*.css" exclude "**/*.min.css" } } } javascript.source.dev.js.files.eachWithIndex { jsFile, i -> tasks.create(name: "minifyJs${i}", type: com.eriwen.gradle.js.tasks.MinifyJsTask) { source = jsFile dest = jsFile //dest = jsFile.getAbsolutePath().replace('.js', '.min.js') } } task allMinifyJs(dependsOn: tasks.matching { Task task -> if( "$targetServer" != "local" ){ task.name.startsWith("minifyJs") } else { println '로컬에서는 minify 하지 않음' } } ) css.source.dev.css.files.eachWithIndex { cssFile, i -> tasks.create(name: "minifyCss${i}", type: com.eriwen.gradle.css.tasks.MinifyCssTask) { source = cssFile dest = cssFile //dest = cssFile.getAbsolutePath().replace('.css','.min.css') yuicompressor { lineBreakPos = -1 } } } task allMinifyCss(dependsOn: tasks.matching { Task task -> if ( "$targetServer" != "local" ){ task.name.startsWith("minifyCss") } else { println '로컬에서는 minify 하지 않음' } } )
Ant
https://github.com/yui/yuicompressor
[build.xml]
<path id="yui.classpath"> <fileset dir="./lib"> <include name="ant-yui-compressor-taskdef-1.0.jar" /> <include name="yuicompressor-2.4.8.jar" /> </fileset> </path> <taskdef resource="yuicompressor.tasks" classpathref="yui.classpath" /> <target name="compress" description="Compress JS files using YUI Compressor"> <!-- Compress JS files using YUI Compressor --> <ant-yui-compressor todir="./webapp/resources/js" deleteOriginal="false"> <fileset dir="./webapp/resources/js"> <include name="**/*.js" /> <include name="**/*.min.js" /> <exclude name="ez-common.js" /> <exclude name="IBSheetPro3/IBSheetInfo_UTF8.js" /> </fileset> <mapper type="glob" from="*.js" to="*.js" /> </ant-yui-compressor> <!-- Compress CSS files using YUI Compressor --> <ant-yui-compressor todir="./webapp/resources/css" deleteOriginal="false"> <fileset dir="./webapp/resources/css"> <include name="**/*.css" /> <include name="**/*.min.css" /> </fileset> <mapper type="glob" from="*.css" to="*.css" /> </ant-yui-compressor> </target>