Skip to content

Instantly share code, notes, and snippets.

@jayhjkwon
Last active May 18, 2017 09:14
Show Gist options
  • Save jayhjkwon/eca46c34697b441a9be4 to your computer and use it in GitHub Desktop.
Save jayhjkwon/eca46c34697b441a9be4 to your computer and use it in GitHub Desktop.
Minification of Require.js modules with ASP.NET Bundling and r.js
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - My ASP.NET Application</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
@Html.ActionLink("Application name", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
</ul>
</div>
</div>
</div>
<div class="container body-content">
@RenderBody()
<hr />
<footer>
<p>&copy; @DateTime.Now.Year - My ASP.NET Application</p>
</footer>
</div>
@Scripts.Render("~/bundles/requirejs", "~/bundles/requirejs_config")
@Scripts.Render("~/bundles/app")
</body>
</html>
require(['./person', 'jquery', 'underscore', 'backbone'], function (person, $, _, Backbone) {
var name = person.getName();
console.log(name);
console.log('app.js');
var View = Backbone.View.extend({
});
var view = new View;
});
({
baseUrl: '../Scripts/app',
name: './app',
out: './app.min.js',
optimize: 'none',
paths: {
jquery: '../lib/jquery-1.10.2',
bootstrap: '../lib/bootstrap',
underscore: '../lib/lodash',
backbone: '../lib/backbone'
},
shim: {
bootstrap: {
deps: ['jquery']
}
}
})
using System.Web;
using System.Web.Optimization;
namespace WebApplication4
{
public class BundleConfig
{
// For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*"));
bundles.Add(new ScriptBundle("~/bundles/requirejs").Include("~/Scripts/lib/require.js"));
bundles.Add(new ScriptBundle("~/bundles/requirejs_config")
.Include("~/Scripts/requirejs_config.js"));
#if DEBUG
bundles.Add(new ScriptBundle("~/bundles/app")
.Include("~/Scripts/app/app.js"));
#else
bundles.Add(new ScriptBundle("~/bundles/app")
.Include("~/Scripts/app.min.js"));
#endif
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/site.css"));
BundleTable.EnableOptimizations = true;
#if DEBUG
BundleTable.EnableOptimizations = false;
#endif
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Antlr" version="3.4.1.9004" targetFramework="net45" />
<package id="Backbone.js" version="1.1.2" targetFramework="net45" />
<package id="bootstrap" version="3.0.0" targetFramework="net45" />
<package id="jQuery" version="1.10.2" targetFramework="net45" />
<package id="jQuery.Validation" version="1.11.1" targetFramework="net45" />
<package id="lodash" version="2.4.1" targetFramework="net45" />
<package id="Microsoft.AspNet.Mvc" version="5.1.2" targetFramework="net45" />
<package id="Microsoft.AspNet.Razor" version="3.1.2" targetFramework="net45" />
<package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net45" />
<package id="Microsoft.AspNet.WebPages" version="3.1.2" targetFramework="net45" />
<package id="Microsoft.jQuery.Unobtrusive.Validation" version="3.1.2" targetFramework="net45" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
<package id="Modernizr" version="2.6.2" targetFramework="net45" />
<package id="Newtonsoft.Json" version="5.0.6" targetFramework="net45" />
<package id="Node.js" version="0.10.29" targetFramework="net45" />
<package id="RequireJS" version="2.1.14" targetFramework="net45" />
<package id="Respond" version="1.2.0" targetFramework="net45" />
<package id="underscore.js" version="1.5.1" targetFramework="net45" />
<package id="WebGrease" version="1.5.2" targetFramework="net45" />
</packages>
define(function () {
var getName = function () {
return 'hyojung';
};
return {
getName: getName
};
});
requirejs.config({
baseUrl: '../scripts/app',
paths: {
jquery: '../lib/jquery-1.10.2',
bootstrap: '../lib/bootstrap',
underscore: '../lib/lodash',
backbone: '../lib/backbone'
},
shim: {
bootstrap: {
deps: ['jquery']
}
}
});
<Target Name="BeforeBuild">
<Exec Command=".bin\node Scripts\lib\r.js -o Scripts\build.js" />
</Target>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment