【问题标题】:Passing options to UglifyJS2 when using Assetic Bundle使用 Assetic Bundle 时将选项传递给 UglifyJS2
【发布时间】:2017-03-04 13:17:50
【问题描述】:

作为标题,在使用 Assetic 时,有没有办法将选项传递给 UglifyJS2?具体来说,我需要传递--comments 选项。

我已尝试将选项添加到我的 config.yml 中的 bin 设置:bin: "%uglifyjs_bin_path% --comments",但这不会运行,因为它试图在路径中包含 --cmets:

[资产\异常\过滤异常]
运行时出错:
'/usr/bin/nodejs' '/usr/local/bin/uglifyjs --cmets' '-o' '/tmp/assetic_uglifyjs2_outyYVBye' '/tmp/assetic_uglifyjs2_ind932Xh' 错误 输出:
模块.js:328

抛出错误;
错误:找不到模块 '/usr/local/bin/uglifyjs --cmets'

在 Function.Module._resolveFilename (module.js:326:15)
在 Function.Module._load (module.js:277:25)
在 Function.Module.runMain (module.js:442:10)
启动时 (node.js:136:18)
在 node.js:966:3

【问题讨论】:

    标签: symfony assetic uglifyjs2


    【解决方案1】:

    在对 Assetic 包的源代码进行一些挖掘之后,我找到了 UglifyJS2 过滤器的配置,UglifyJS2 Configuration。多亏了这一点,我才发现要启用 cmets 选项,我只需要将它与 bin 选项一起传递,如下所示:

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

    编辑:此外,如果您想将参数传递给给定选项,您只需将参数传递给想要的选项,选项本身就会自动添加。例如,我正在使用自定义正则表达式运行 cmets:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-22
      • 2011-03-11
      • 1970-01-01
      • 2012-12-17
      • 1970-01-01
      • 2012-06-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多