我正在使用优秀的eriwen gradle.js plugin来组合然后缩小我的js。
在 build.gradle 文件中,我有
plugins {
id "com.eriwen.gradle.css" version "1.11.1"
id "com.eriwen.gradle.js" version "1.12.1"
}
// other stuff
def jsSrcDir = 'src/main/webapp/js'
combineJs {
source = fileTree(jsSrcDir)
dest = file('all.js')
}
minifyJs {
source = combineJs
dest = file('all-min.js')
sourceMap = file('all.sourcemap.js')
closure {
warningLevel = 'QUIET'
compilerOptions.languageIn = "ECMASCRIPT5"
}
}
当我运行gradle minfyJs
时,在我的源地图中我有
"sources":["/home/userb/projects/alpha1/all.js"],
如果我使用uglifyjs(如here所述),我结束了
uglifyjs src/main/webapp/**/*.js --source-map sourceMap.json -o blah.js
sourceMap.json包含
"sources":["src/main/webapp/bootstrap3-js/bootstrap.js","src/main/webapp/bootstrap3-js/bootstrap.min.js","src/main/webapp/bootstrap3-js/jquery-2.1.1.js","src/main/webapp/bootstrap3-js/postrope-global.js","src/main/webapp/bootstrap3-js/snap.js","src/main/webapp/bootstrap3-js/snap.min.js","src/main/webapp/js/analytics.js","src/main/webapp/js/BlobBuilder.js","src/main/webapp/js/Blob.js","src/main/webapp/js/bootstrap2.2.1.js","src/main/webapp/js/bootstrap2.3.2.js","src/main/webapp/js/bootstrap.file-upload.js","src/main/webapp/js/bootstrap-modal-enhance.js","src/main/webapp/js/bootstrap-select.min.js","src/main/webapp/js/bootstrap-transition.js","src/main/webapp/js/canvas-toBlob.js","src/main/webapp/js/cbpSplitLayout.js","src/main/webapp/js/classie.js","src/main/webapp/js/countries.en.js","src/main/webapp/js/custom-animation.js","src/main/webapp/js/jquery-1.8.3.min.js","src/main/webapp/js/jquery-1.9.1.js","src/main/webapp/js/jquery.autocomplete.js","src/main/webapp/js/jquery.blockUI.js","src/main/webapp/js/jQuery.circleMenu.js","src/main/webapp/js/jquery.clingify.min.js","src/main/webapp/js/jquery-color.js","src/main/webapp/js/jquery.confirm2.js","src/main/webapp/js/jquery.confirm.js","src/main/webapp/js/jquery.confirm.min.js","src/main/webapp/js/jquery.fileupload.js","src/main/webapp/js/jquery.flexslider.js","src/main/webapp/js/jquery.iframe-transport.js","src/main/webapp/js/jquery.masonry.min.js","src/main/webapp/js/jquery.timeago.js","src/main/webapp/js/jquery.ui.widget.min.js","src/main/webapp/js/jquery.unveil.js","src/main/webapp/js/jquery.waitforimages.js","src/main/webapp/js/jquery.wookmark.js","src/main/webapp/js/livestamp.min.js","src/main/webapp/js/location.js","src/main/webapp/js/main.js","src/main/webapp/js/modernizr-2.6.2.js","src/main/webapp/js/modernizr.custom2.js","src/main/webapp/js/modernizr.custom.js","src/main/webapp/js/moment.min.js","src/main/webapp/js/offer.js","src/main/webapp/js/parsley.js","src/main/webapp/js/ProgressButtons.js","src/main/webapp/js/raphael.js","src/main/webapp/js/register.js","src/main/webapp/js/rope_utility.js","src/main/webapp/js/signup_utility.js","src/main/webapp/js/static-jquery.js","src/main/webapp/js/static-jquery.mega.js","src/main/webapp/js/static-jquery-migrate.min.js","src/main/webapp/js/utility.js","src/main/webapp/js/waypoints.min.js"]
uglify的结果就是我想要的。它跟踪我的源图中的所有源文件,因此我可以更快地识别我的JS中的错误。 我想知道我是否可以通过gradle插件获得类似的结果?我不想从我的gradle任务中运行uglify - 我宁愿修改gradle插件来做我想做的事。懒惰虽然我不想写任何代码如果gradle插件已经这样做了。
我可以使用gradle插件实现uglifyJs结果吗?
答案 0 :(得分:1)
可悲的是,该插件的文档不是很好。 只是不要使用combineJs,minifyJs也能够组合来源:
minifyJs {
source = fileTree(jsSrcDir)
dest = file('all-min.js')
sourceMap = file('all.sourcemap.js')
closure {
warningLevel = 'QUIET'
compilerOptions.languageIn = "ECMASCRIPT5"
}
}