Skip to content

Commit a2a5eb8

Browse files
author
Edward Ridge
committed
Concatenation and minification
1 parent 1dab9af commit a2a5eb8

4 files changed

Lines changed: 66 additions & 7 deletions

File tree

‎Gulp and Visual Studio/Gulp and Visual Studio.csproj‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,11 @@
124124
<Content Include="favicon.ico" />
125125
<Content Include="fonts\glyphicons-halflings-regular.svg" />
126126
<Content Include="Global.asax" />
127+
<Content Include="gulpfile.js" />
127128
<Content Include="Scripts\Libraries\bootstrap.js" />
128129
<Content Include="Scripts\Libraries\bootstrap.min.js" />
129130
<Content Include="Scripts\Libraries\jquery.js" />
131+
<Content Include="package.json" />
130132
<None Include="Scripts\Libraries\jquery.validate-vsdoc.js" />
131133
<Content Include="Scripts\Libraries\jquery.validate.js" />
132134
<Content Include="Scripts\Libraries\jquery.validate.min.js" />
@@ -176,7 +178,7 @@
176178
<VisualStudio>
177179
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
178180
<WebProjectProperties>
179-
<UseIIS>True</UseIIS>
181+
<UseIIS>False</UseIIS>
180182
<AutoAssignPort>True</AutoAssignPort>
181183
<DevelopmentServerPort>56830</DevelopmentServerPort>
182184
<DevelopmentServerVPath>/</DevelopmentServerVPath>
@@ -191,10 +193,24 @@
191193
<UserProperties package_1json__JSONSchema="http://json.schemastore.org/resjson" />
192194
</VisualStudio>
193195
</ProjectExtensions>
196+
<PropertyGroup>
197+
<PreBuildEvent>if $(ConfigurationName) == Release (
198+
cd $(ProjectDir)
199+
npm install
200+
gulp minifyFilesForRelease
201+
202+
)
203+
</PreBuildEvent>
204+
</PropertyGroup>
194205
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
195206
Other similar extension points exist, see Microsoft.Common.targets.
196207
<Target Name="BeforeBuild">
197208
</Target>
198209
<Target Name="AfterBuild">
199210
</Target> -->
211+
<Target Name="AfterBuild">
212+
<ItemGroup>
213+
<Content Include="dist\*.*" />
214+
</ItemGroup>
215+
</Target>
200216
</Project>

‎Gulp and Visual Studio/Views/Shared/_Layout.cshtml‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
<meta charset="utf-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66
<title>@ViewBag.Title - My ASP.NET Application</title>
7+
78
<!-- build:css /dist/site.css -->
8-
<link href="~/Content/bootstrap.css" rel="stylesheet" />
9-
<link href="~/Content/Site.css" rel="stylesheet" />
9+
<link href="/Content/bootstrap.css" rel="stylesheet" />
10+
<link href="/Content/Site.css" rel="stylesheet" />
1011
<!-- endbuild -->
1112

1213
</head>
@@ -38,9 +39,9 @@
3839
</footer>
3940
</div>
4041
<!-- build:js /dist/libs.js -->
41-
<script src="~/Scripts/Libraries/jquery.js"></script>
42-
<script src="~/Scripts/Libraries/bootstrap.js"></script>
43-
<script src="~/Scripts/Libraries/respond.js"></script>
42+
<script src="/Scripts/Libraries/jquery.js"></script>
43+
<script src="/Scripts/Libraries/bootstrap.js"></script>
44+
<script src="/Scripts/Libraries/respond.js"></script>
4445
<!-- endbuild -->
4546
@RenderSection("scripts", required: false)
4647
</body>

‎Gulp and Visual Studio/gulpfile.js‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,41 @@ gulp.task('sass', function () {
1212
;
1313
});
1414

15+
gulp.task('minifyFilesForRelease', function () {
16+
17+
var cssFilter = plugins.filter('**/*.css', { restore: true });
18+
var jsFilter = plugins.filter('**/*.js', { restore: true });
19+
20+
var assets = plugins.useref.assets();
21+
gulp.src('./**/*.cshtml')
22+
.pipe(assets)
23+
24+
//Process JavaScript
25+
.pipe(jsFilter)
26+
.pipe(plugins.uglify())
27+
.pipe(plugins.rev())
28+
.pipe(assets.restore())
29+
.pipe(jsFilter.restore)
30+
31+
//Process CSS
32+
.pipe(cssFilter)
33+
.pipe(plugins.minifyCss({
34+
keepSpecialComments: 0
35+
}))
36+
.pipe(plugins.rev())
37+
.pipe(assets.restore())
38+
.pipe(cssFilter.restore)
39+
40+
.pipe(plugins.useref())
41+
.pipe(plugins.revReplace({
42+
replaceInExtensions: ['.js', '.css', '.html', '.cshtml']
43+
}))
44+
.pipe(gulp.dest(function (data) {
45+
return data.base;
46+
}
47+
));
48+
});
49+
1550
gulp.task('watch-sass', function () {
1651
plugins.livereload.listen();
1752
gulp.watch('./Content/*.scss', ['sass']);

‎Gulp and Visual Studio/package.json‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
"gulp-sass": "~2.0.4",
88
"gulp-sourcemaps": "~1.5.2",
99
"gulp-autoprefixer": "~2.3.1",
10-
"gulp-livereload": "~3.8.0"
10+
"gulp-livereload": "~3.8.0",
11+
"gulp-useref": "~1.3.0",
12+
"gulp-uglify": "~1.2.0",
13+
"gulp-minify-css": "~1.2.1",
14+
"gulp-rev": "~5.1.0",
15+
"gulp-rev-replace": "~0.4.2",
16+
"gulp-filter": "~3.0.0"
17+
1118
}
1219
}

0 commit comments

Comments
 (0)