我想缩小和混淆我的Web应用程序(而不是MVC)的javascript文件。我的代码基于这个简单的配置:https://bundletransformer.codeplex.com/discussions/541419,但是 从浏览器查看时,它似乎对js文件没有影响。我不明白Bundle Transformer是否只适用于MVC Web应用程序。我安装了BundleTransformer.Core,BundleTransformer.Yui,Microsoft.AspNet.Web.Optimization。
的Global.asax.cs:
public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
var nullOrderer = new NullOrderer();
var scriptBundle = new CustomScriptBundle("~/jscbundle/");
scriptBundle.Include("~/js/main.js");
scriptBundle.IncludeDirectory("~/js/", "*.js", true);
scriptBundle.Orderer = nullOrderer;
bundles.Add(scriptBundle);
BundleTable.EnableOptimizations = true;
}
}
protected void Application_Start(object sender, EventArgs e)
{
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
Web.Config中:
<system.web>
<compilation debug="false" targetFramework="4.5" />
...
</system.web>
<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="YuiJsMinifier">
<minifiers>
<add name="NullMinifier" type="BundleTransformer.Core.Minifiers.NullMinifier, BundleTransformer.Core" />
<add name="YuiJsMinifier" type="BundleTransformer.Yui.Minifiers.YuiJsMinifier, BundleTransformer.Yui" />
</minifiers>
<translators>
<add name="NullTranslator" type="BundleTransformer.Core.Translators.NullTranslator, BundleTransformer.Core" enabled="false" />
</translators>
</js>
</core>
</bundleTransformer>