2017-03-04 42 views
0

作爲標題,在使用Assetic時有什麼方法將選項傳遞給UglifyJS2?具體而言,我需要通過--comments選項。當使用Assetic Bundle時將選項傳遞給UglifyJS2

我試圖將選項添加到我的config.yml垃圾桶設置:bin: "%uglifyjs_bin_path% --comments",而是因爲它試圖在路徑中包含--comments不會運行:

[Assetic\Exception\FilterException]
An error occurred while running:
'/usr/bin/nodejs' '/usr/local/bin/uglifyjs --comments' '-o' '/tmp/assetic_ uglifyjs2_outyYVBye' '/tmp/assetic_uglifyjs2_ind932Xh' Error Output:
module.js:328

throw err;
Error: Cannot find module '/usr/local/bin/uglifyjs --comments'

at Function.Module._resolveFilename (module.js:326:15)
at Function.Module._load (module.js:277:25)
at Function.Module.runMain (module.js:442:10)
at startup (node.js:136:18)
at node.js:966:3

回答

4

經過一番挖掘資產包的源代碼我發現了UglifyJS2過濾器的配置,UglifyJS2 Configuration。多虧了我能弄清楚,使評論選項,我只是需要與bin選項一起傳遞,就像這樣:

uglifyjs2: 
     # the path to the uglifyjs executable 
     bin: "%uglifyjs_bin_path%" 
     comments: true 

編輯:另外,如果你想傳遞參數給定選項只是將參數傳遞給想要的選項,而選項本身將自動添加。我例如運行自定義正則表達式的評論:

uglifyjs2: 
     # the path to the uglifyjs executable 
     bin: "%uglifyjs_bin_path%" 
     comments: /^\/*\**!/ 
     compress: true 
     mangle: true 
相關問題