简体   繁体   中英

minimize js files in gradle build while creating a war

I am completely new to gradle and I am manage to create war through gradle-4.2.1 by following scripts :

apply plugin: 'war'
archivesBaseName = "idcapture"
version = '1.0' 
webAppDirName = 'WebContent'
buildDir = 'gradle_Build'

 sourceSets {
  main {
     java {
          srcDir 'src'
     }
     resources {
       srcDir 'conf'
     }
  } 
}

dependencies {
  compile fileTree(dir: "WebContent/WEB-INF/lib", include: '*.jar')
   }

I can able to create an war file by above code but my intention the war file should have minimized version of JS files. Hence I have tried n number of places. I tried erwin js plugin and I am unable to implement:
fyr, https://github.com/eriwen/gradle-js-plugin

Especially I am not able to point the js file paths and minimize function my script. The errors are various and I am not sure where to place that in my script!! Fyr, my application folder structure attached

主项目文件夹结构
js文件夹结构

any help would be appreciated. Thanks

I found it, if we add following erwil libs on any place of the build. it works fine:

    plugins {
    id 'com.eriwen.gradle.js' version '2.14.1'
}


import com.eriwen.gradle.js.tasks.MinifyJsTask
task minifyJS << {
    println "lets minify"
  fileTree('WebContent/js').eachWithIndex { file, index ->
    def dynamicTask = "minify$index"
    task "$dynamicTask" (type: MinifyJsTask) {
      source = file
      dest = file
    }
    tasks."$dynamicTask".execute()
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM