[英]Is it possible to exclude parts of javascript with grunt-contrib-uglify?
我正在為我的 js 構建過程使用grunt-contrib-uglify ,並且非常希望能夠從最終構建中排除某些代碼部分。
所以看起來像:
/*BuildExcludeBegin*/
Run this code during development, but don't include it in the minified.js
/*BuildExcludeEnd*/
有誰知道這對 grunt-contrib-uglify 是否可行?
grunt-contrib-uglify不提供。 但你可以使用: https : //www.npmjs.com/package/grunt-strip-code
從該頁面引用:
grunt-strip-代碼
grunt-strip-code 插件用於從生產構建中刪除僅在開發和測試環境中需要的代碼部分。 grunt-strip-code 使用開始和結束注釋來標識要刪除的代碼部分。 例如:
/* test-code */
removeMeInProduction();
/* end-test-code */
doNotRemoveMe();
此實踐的一個用例是使單元測試可以訪問私有 JavaScript 函數,而無需在生產版本中公開它們。 這篇博文更詳細地介紹了概念和實現。
我認為沒有允許您排除代碼片段的功能。 您可以將代碼拆分為可以單獨排除的單獨文件嗎? 並且mangle或mangle.properties 不適合您嗎?
它可以用grunt-contrib-uglify來完成,它現在被稱為條件編譯,就像......
if (DEBUG) {
console.log("debug stuff");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.