'Gradle'에 해당되는 글 1건

  1. 2014.02.19 Gradle에서 CoffeeScript 컴파일하기

CoffeeScript는 *.coffee를 *.js로 컴파일을 해줘서 사용한다.


이 컴파일을 하는 방법에는 여러가지가 있다. 


Maven의 경우에는 특별히 자동화된 방법이 있는 듯하고, 그 외에도 커맨드 라인 툴로 수동 컴파일을 해도 나쁘지 않다.


그런데 Gradle을 사용하는 경우에는 어떻게 해야하는지에 대해 자료가 극히 적었다.


구글을 아무리 뒤져봐도 이게 관한 자료는 쓸만한게 대략 2가지 정도 나오는데 전부 동작하지 않았다.


 서론은 여기까지 하고 결과만 보자면 다음과 같다.


apply plugin: 'coffeescript-base' // CoffeeScript 컴파일을 위한 플러그인 def coffeeScriptDestinationDir = 'src/main/webapp/resources/js/coffee' task compileCoffee(type: CoffeeScriptCompile) { coffeeScriptJs = 'src/main/coffee/compiler/coffee-script.js' // CoffeeScriptCompiler destinationDir = coffeeScriptDestinationDir source = fileTree('src/main/coffee/scripts') // *.coffee 스크립트의 위치 } clean { delete coffeeScriptDestinationDir // clean Task시 컴파일된 js 삭제 }


이후 CoffeeScript 컴파일이 필요할 때 compileCoffee Task를 실행하면 된다. 


CoffeeScriptCompile 클래스는 Gradle 측에서 개발한 공식 플러그인이다. 


apply plugin: 'coffeescript-base' 을 입력해주면 사용이 가능하다.


wro4j같이 외부 라이브러리와 Coffee 바이너리를 이용할 수도 있지만 웬만하면 공식 Plugin을 사용하는 것이 나을 듯하다.



Posted by Liliniser
: