我刚刚添加了 BundleTransformer.UglifyJs NuGet package到我的 MVC 项目来混淆 javascript 代码。
但是结果看起来不是很丑:
function onDeckenstaerkeChanged(){validateCorrectDeckenstaerke();$("#dropdown-bta").empty();$.each(getBelagtraegerAbstand(
这是我的 web.config 中配置 minifier 的部分:
<bundleTransformer xmlns="http://tempuri.org/BundleTransformer.Configuration.xsd">
<core>
<css>
<minifiers>
<add name="NullMinifier" type="BundleTransformer.Core.Minifiers.NullMinifier, BundleTransformer.Core" />
<add name="YuiCssMinifier" type="BundleTransformer.Yui.Minifiers.YuiCssMinifier, BundleTransformer.Yui" /></minifiers>
<translators>
<add name="NullTranslator" type="BundleTransformer.Core.Translators.NullTranslator, BundleTransformer.Core" enabled="false" />
</translators>
</css>
<js defaultMinifier="UglifyJsMinifier">
<minifiers>
<add name="NullMinifier" type="BundleTransformer.Core.Minifiers.NullMinifier, BundleTransformer.Core" />
<add name="YuiJsMinifier" type="BundleTransformer.Yui.Minifiers.YuiJsMinifier, BundleTransformer.Yui" />
<add name="UglifyJsMinifier" type="BundleTransformer.UglifyJs.Minifiers.UglifyJsMinifier, BundleTransformer.UglifyJs" />
</minifiers>
<translators>
<add name="NullTranslator" type="BundleTransformer.Core.Translators.NullTranslator, BundleTransformer.Core" enabled="false" />
</translators>
</js>
</core>
</bundleTransformer>
对我来说,结果看起来很精简,但没有混淆。
我错过了什么,结果应该是什么样的?
有没有办法调试使用了哪个模块?
最佳答案
如前所述here :
As a JS-engine is used the JavaScript Engine Switcher library. For correct working of this module is recommended to install one of the following NuGet packages: JavaScriptEngineSwitcher.Msie or JavaScriptEngineSwitcher.V8. After package is installed, need set a name of JavaScript engine (for example, MsieJsEngine) to the name attribute of /configuration/bundleTransformer/uglify/jsEngine configuration element.
要使 Bundle Transformer UglifyJS 正常工作,您需要安装 JS 引擎,并且在您的 web.config 片段中我没有看到它已定义。因此,安装 JavaScriptEngineSwitcher.Msie或 JavaScriptEngineSwitcher.V8包。
重要!
根据您安装的包,您必须在 V8 的 web.config 片段末尾手动添加:
...
</core>
<uglify>
<jsEngine name="V8JsEngine"></jsEngine>
</uglify>
</bundleTransformer>
或者对于 MsieJsEngine:
...
</core>
<uglify>
<jsEngine name="MsieJsEngine"></jsEngine>
</uglify>
</bundleTransformer>
关于使用 BundleTransformer.UglifyJs 混淆 Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24054299/