Last active
August 31, 2018 11:49
-
-
Save smockle/7101419 to your computer and use it in GitHub Desktop.
Demonstrates how to use BundleTransformer in a C# ASP.NET MVC web application.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Web; | |
using System.Web.Optimization; | |
using BundleTransformer.Core.Transformers; | |
namespace Project.App_Start { | |
public class BundleConfig { | |
public static void RegisterBundles(BundleCollection bundles) { | |
var styles = new Bundle("~/bundles/stylesheets") | |
.Include( | |
"~/Assets/Styles/*.css", | |
"~/Assets/Styles/application.less" | |
); | |
styles.Transforms.Add(new CssTransformer()); | |
bundles.Add(styles); | |
var scripts = new ScriptBundle("~/bundles/javascripts") | |
.Include( | |
"~/Assets/Scripts/*.js", | |
"~/Assets/Scripts/*.coffee" | |
); | |
scripts.Transforms.Add(new JsTransformer()); | |
bundles.Add(scripts); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Project.App_Start; | |
using System.Web.Optimization; | |
protected void Application_Start() { | |
BundleConfig.RegisterBundles(BundleTable.Bundles); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%: System.Web.Optimization.Styles.Render("~/bundles/stylesheets") %> | |
<%: System.Web.Optimization.Scripts.Render("~/bundles/javascripts") %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Install-Package BundleTransformer.Less | |
Install-Package BundleTransformer.SassAndScss | |
Install-Package BundleTransformer.CoffeeScript | |
Install-Package JavaScriptEngineSwitcher.V8 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<pages> | |
<namespaces> | |
<add namespace="System.Web.Optimization" /> | |
</namespaces> | |
</pages> | |
<bundleTransformer xmlns="http://tempuri.org/BundleTransformer.Configuration.xsd"> | |
<core> | |
<css> | |
<minifiers> | |
<add name="NullMinifier" type="BundleTransformer.Core.Minifiers.NullMinifier, BundleTransformer.Core" /> | |
</minifiers> | |
<translators> | |
<add name="NullTranslator" type="BundleTransformer.Core.Translators.NullTranslator, BundleTransformer.Core" enabled="false" /> | |
<add name="LessTranslator" type="BundleTransformer.Less.Translators.LessTranslator, BundleTransformer.Less" /> | |
<add name="SassAndScssTranslator" type="BundleTransformer.SassAndScss.Translators.SassAndScssTranslator, BundleTransformer.SassAndScss" /> | |
</translators> | |
</css> | |
<js> | |
<minifiers> | |
<add name="NullMinifier" type="BundleTransformer.Core.Minifiers.NullMinifier, BundleTransformer.Core" /> | |
</minifiers> | |
<translators> | |
<add name="NullTranslator" type="BundleTransformer.Core.Translators.NullTranslator, BundleTransformer.Core" enabled="false" /> | |
<add name="CoffeeScriptTranslator" type="BundleTransformer.CoffeeScript.Translators.CoffeeScriptTranslator, BundleTransformer.CoffeeScript" /> | |
</translators> | |
</js> | |
</core> | |
<less> | |
<jsEngine name="V8JsEngine" /> | |
</less> | |
<coffeeScript> | |
<jsEngine name="V8JsEngine" /> | |
</coffeeScript> | |
</bundleTransformer> | |
<jsEngineSwitcher xmlns="http://tempuri.org/JavaScriptEngineSwitcher.Configuration.xsd"> | |
<core> | |
<engines> | |
<add name="V8JsEngine" type="JavaScriptEngineSwitcher.V8.V8JsEngine, JavaScriptEngineSwitcher.V8" /> | |
</engines> | |
</core> | |
</jsEngineSwitcher> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment