Skip to content

Commit 191a2de

Browse files
committed
Add basic view controller (not wired up yet). Add CSS, JS minification, combination and injection.
1 parent ec144e5 commit 191a2de

File tree

10 files changed

+153
-14
lines changed

10 files changed

+153
-14
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,12 @@ FakesAssemblies/
210210
GeneratedArtifacts/
211211
_Pvt_Extensions/
212212
ModelManifest.xml
213+
214+
# Project-specific exclusions
215+
216+
# Bower packages
217+
wwwroot/lib/
218+
# Minified JS - created by gulp task
219+
wwwroot/js/*.min.js
220+
# Minified CSS - created by gulp task
221+
wwwroot/css/*.min.css
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNet.Mvc;
6+
7+
// For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
8+
9+
namespace AngularGettingStarted.Controllers
10+
{
11+
public class HomeController : Controller
12+
{
13+
// GET: /<controller>/
14+
public IActionResult Index()
15+
{
16+
return View();
17+
}
18+
}
19+
}

src/AngularGettingStarted/Startup.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
using Microsoft.AspNet.Builder;
66
using Microsoft.AspNet.Http;
77
using Microsoft.Framework.DependencyInjection;
8+
using Microsoft.AspNet.Hosting;
89

910
namespace AngularGettingStarted
1011
{
1112
public class Startup
1213
{
1314
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
14-
public void ConfigureServices(IServiceCollection services)
15+
public void ConfigureServices(IServiceCollection services, IHostingEnvironment env)
1516
{
1617
services.AddMvc();
1718
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@*
2+
For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
3+
*@
4+
@{
5+
// ViewBag.Title = "Home Page";
6+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
@inject Microsoft.AspNet.Hosting.IHostingEnvironment HostingEnvironment
2+
<!DOCTYPE html>
3+
4+
<html>
5+
<head>
6+
<meta name="viewport" content="width=device-width" />
7+
<title>@ViewBag.Title</title>
8+
@if (HostingEnvironment.EnvironmentName == "Development") {
9+
10+
<!-- inject:css -->
11+
<link rel="stylesheet" href="/css/src/site.css">
12+
<!-- endinject -->
13+
<!-- inject:js -->
14+
<script src="/lib/angular/angular.min.js"></script>
15+
<script src="/lib/angular-ui-router/release/angular-ui-router.min.js"></script>
16+
<!-- endinject -->
17+
<!-- app:js -->
18+
<script src="/js/src/app.js"></script>
19+
<!-- endinject -->
20+
21+
}
22+
@if (HostingEnvironment.EnvironmentName != "Development") {
23+
<!-- min:css -->
24+
<link rel="stylesheet" href="/css/app.min.css">
25+
<!-- endinject -->
26+
<!-- min:js -->
27+
<script src="/js/libs.min.js"></script>
28+
<script src="/js/app.min.js"></script>
29+
<!-- endinject -->
30+
}
31+
</head>
32+
<body>
33+
<div>
34+
@RenderBody()
35+
</div>
36+
</body>
37+
</html>

src/AngularGettingStarted/bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ASP.NET",
3-
"private": true,
3+
"private": true,
44
"dependencies": {
55
"angular": "~1.5.0",
66
"angular-ui-router": "~0.2.15"

src/AngularGettingStarted/gulpfile.js

Lines changed: 71 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,37 @@
1-
/// <binding Clean='clean' />
1+
/// <binding BeforeBuild='min' Clean='clean' />
22

33
var gulp = require("gulp"),
44
rimraf = require("rimraf"),
55
concat = require("gulp-concat"),
66
cssmin = require("gulp-cssmin"),
77
uglify = require("gulp-uglify"),
8+
inject = require("gulp-inject"),
9+
angularFilesort = require("gulp-angular-filesort"),
810
project = require("./project.json");
911

1012
var paths = {
11-
webroot: "./" + project.webroot + "/"
13+
webroot: "./" + project.webroot + "/",
1214
};
1315

14-
paths.js = paths.webroot + "js/**/*.js";
15-
paths.minJs = paths.webroot + "js/**/*.min.js";
16-
paths.css = paths.webroot + "css/**/*.css";
17-
paths.minCss = paths.webroot + "css/**/*.min.css";
18-
paths.concatJsDest = paths.webroot + "js/site.min.js";
19-
paths.concatCssDest = paths.webroot + "css/site.min.css";
16+
paths.js = [paths.webroot + "js/src/**/*.js"];
17+
paths.css = [paths.webroot + "css/src/**/*.css"];
18+
paths.concatJsDest = paths.webroot + "js/app.min.js";
19+
paths.concatCssDest = paths.webroot + "css/app.min.css";
20+
21+
paths.htmlInject = ["./Views/**/*.cshtml"];
22+
23+
// When adding Bower dependencies, ensure that whatever JS and CSS files
24+
// they provide are added to this list.
25+
paths.libJs = [
26+
paths.webroot + 'lib/angular/angular.min.js',
27+
paths.webroot + 'lib/angular-ui-router/release/angular-ui-router.min.js'
28+
];
29+
paths.libCss = [];
30+
31+
paths.concatLibJsDest = paths.webroot + "js/libs.min.js";
32+
paths.concatLibCssDest = paths.webroot + "css/libs.min.css";
33+
34+
paths.concatAll = [paths.concatLibCssDest, paths.concatCssDest, paths.concatLibJsDest, paths.concatJsDest];
2035

2136
gulp.task("clean:js", function (cb) {
2237
rimraf(paths.concatJsDest, cb);
@@ -26,20 +41,64 @@ gulp.task("clean:css", function (cb) {
2641
rimraf(paths.concatCssDest, cb);
2742
});
2843

29-
gulp.task("clean", ["clean:js", "clean:css"]);
44+
gulp.task("clean:libJs", function (cb) {
45+
rimraf(paths.concatLibJsDest, cb);
46+
});
47+
48+
gulp.task("clean:libCss", function (cb) {
49+
rimraf(paths.concatLibCssDest, cb);
50+
});
51+
52+
gulp.task("clean", ["clean:js", "clean:css", "clean:libJs", "clean:libCss"]);
3053

3154
gulp.task("min:js", function () {
32-
gulp.src([paths.js, "!" + paths.minJs], { base: "." })
55+
gulp.src(paths.js, { base: "." })
56+
.pipe(angularFilesort())
3357
.pipe(concat(paths.concatJsDest))
3458
.pipe(uglify())
3559
.pipe(gulp.dest("."));
3660
});
3761

3862
gulp.task("min:css", function () {
39-
gulp.src([paths.css, "!" + paths.minCss])
63+
gulp.src(paths.css, { base: "." })
4064
.pipe(concat(paths.concatCssDest))
4165
.pipe(cssmin())
4266
.pipe(gulp.dest("."));
4367
});
4468

45-
gulp.task("min", ["min:js", "min:css"]);
69+
gulp.task("min:libJs", function () {
70+
gulp.src(paths.libJs, { base: "." })
71+
.pipe(concat(paths.concatLibJsDest))
72+
.pipe(gulp.dest("."));
73+
});
74+
75+
gulp.task("min:libCss", function () {
76+
gulp.src(paths.libCss, { base: "." })
77+
.pipe(concat(paths.concatLibCssDest))
78+
.pipe(cssmin())
79+
.pipe(gulp.dest("."));
80+
});
81+
82+
gulp.task("min", ["min:js", "min:css", "min:libJs", "min:libCss"]);
83+
84+
//gulp.task("inject", ["inject:libJsAndCss", "inject:appJs"]);
85+
86+
gulp.task("inject", ["min"], function () {
87+
// JS libs then CSS libs then our CSS
88+
var sources = gulp.src(paths.libJs.concat(paths.libCss).concat(paths.css), { base: ".", read: false });
89+
var appSources = gulp.src(paths.js, { base: "." }).pipe(angularFilesort());
90+
var minSources = gulp.src(paths.concatAll, { base: ".", read: false });
91+
gulp.src(paths.htmlInject, { base: "." })
92+
.pipe(inject(sources, { ignorePath: project.webroot }))
93+
.pipe(inject(appSources, { name: "app", ignorePath: project.webroot }))
94+
.pipe(inject(minSources, { name: "min", ignorePath: project.webroot }))
95+
.pipe(gulp.dest("."));
96+
});
97+
/*
98+
gulp.task("inject:appJs", function () {
99+
// Our sorted angular JS
100+
gulp.src(paths.htmlInject, { base: "." })
101+
.pipe(inject(sources, { name: "app" }))
102+
.pipe(gulp.dest("."));
103+
});
104+
*/

src/AngularGettingStarted/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"gulp-concat": "~2.6.0",
88
"gulp-cssmin": "~0.1.7",
99
"gulp-uglify": "~1.4.1",
10+
"gulp-inject": "~3.0.0",
11+
"gulp-angular-filesort": "~1.1.1",
1012
"rimraf": "~2.4.3"
1113
}
1214
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
body {
2+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(function () {
2+
'use strict';
3+
angular.module("app", ['ui.router']);
4+
})();

0 commit comments

Comments
 (0)