Skip to content

Commit

Permalink
Merge pull request #120 from ezraroi/23-enable-scripts-and-css-name-h…
Browse files Browse the repository at this point in the history
…ashing-to-solve-caching-issues

added
  • Loading branch information
ezraroi authored Sep 15, 2024
2 parents a989f43 + 8a18eb6 commit a62ade5
Show file tree
Hide file tree
Showing 251 changed files with 65,705 additions and 5 deletions.
14 changes: 11 additions & 3 deletions Mundialito/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@model Mundialito.Configuration.Config
@inject Microsoft.AspNetCore.Hosting.IHostingEnvironment env

Check warning on line 1 in Mundialito/Views/Home/Index.cshtml

View workflow job for this annotation

GitHub Actions / build

'IHostingEnvironment' is obsolete: 'This type is obsolete and will be removed in a future version. The recommended alternative is Microsoft.AspNetCore.Hosting.IWebHostEnvironment.'
@model Mundialito.Configuration.Config

<!DOCTYPE html>
<html lang="en" ng-app="mundialitoApp">
Expand Down Expand Up @@ -141,8 +142,15 @@
<!-- End of Content Loading message -->
</div>
<!-- End of Main Content -->
<script src="lib/lib.js"></script>
<script src="js/app.js"></script>
@if (env.IsProduction())
{
<script src="lib/lib-min-2d5e40df8764ea1d842fca768d139b58.js"></script>
<script src="js/app-min-6c10cabb3a2ab76eb865c995f6947679.js"></script>
}
else {
<script src="lib/lib-77990d6df268e8d3d432fb52597000f9.js"></script>
<script src="js/app-5e44a1b15c1cfae702ee2652dd5f5edc.js"></script>
}
</div>
</body>
Expand Down
65 changes: 64 additions & 1 deletion Mundialito/gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
const fs = require('node:fs');
const path = require('node:path');
const gulp = require('gulp');
const concat = require('gulp-concat');
const cleanCss = require('gulp-minify-css');
const minify = require('gulp-minify');
const hash = require('gulp-hash-filename');
const replace = require('gulp-replace');
const clean = require('gulp-clean');
const { console } = require('node:inspector');

const allCss = [
"Client/css/angular-busy.css",
Expand Down Expand Up @@ -69,6 +75,7 @@ gulp.task('compress-lib', function () {
])
.pipe(concat('lib.js'))
.pipe(minify())
.pipe(hash())
.pipe(gulp.dest('wwwroot/lib'))
});

Expand All @@ -80,6 +87,7 @@ gulp.task('compress-app', function () {
])
.pipe(concat('app.js'))
.pipe(minify())
.pipe(hash())
.pipe(gulp.dest('wwwroot/js'))
});

Expand All @@ -93,4 +101,59 @@ gulp.task('copy-templates', function () {
.pipe(gulp.dest('wwwroot/'));
});

gulp.task('default', gulp.series(['build-css-cerulean', 'build-css-space-lab', 'compress-lib', 'compress-app', 'copy-html', 'copy-templates']));
gulp.task('cache-bust-lib', () => {
const libPattern = /^lib-[a-z0-9]+\.js$/;
let lib = fs.readdirSync('wwwroot/lib').filter(fileName => {
return libPattern.test(fileName);
});
if (lib.length != 1) {
throw new Error('There should be exactly one lib file');
}
return gulp.src('Views/Home/Index.cshtml')
.pipe(replace(/lib-[a-z0-9]+\.js/, lib[0]))
.pipe(gulp.dest('Views/Home'));
});

gulp.task('cache-bust-lib-min', () => {
const libMinPattern = /^lib-min-[a-z0-9]+\.js$/;
let libMinified = fs.readdirSync('wwwroot/lib').filter(fileName => {
return libMinPattern.test(fileName);
});
if (libMinified.length != 1) {
throw new Error('There should be exactly one lib-min file');
}
return gulp.src('Views/Home/Index.cshtml')
.pipe(replace(/lib-min-[a-z0-9]+\.js/, libMinified[0]))
.pipe(gulp.dest('Views/Home'));
});

gulp.task('cache-bust-app', () => {
const appPattern = /^app-[a-z0-9]+\.js$/;
let app = fs.readdirSync('wwwroot/js').filter(fileName => {
return appPattern.test(fileName);
});
if (app.length != 1) {
throw new Error('There should be exactly one app file');
}
return gulp.src('Views/Home/Index.cshtml')
.pipe(replace(/app-[a-z0-9]+\.js/, app[0]))
.pipe(gulp.dest('Views/Home'));
});

gulp.task('cache-bust-app-min', () => {
const appMinPattern = /^app-min-[a-z0-9]+\.js$/;
let appMinified = fs.readdirSync('wwwroot/js').filter(fileName => {
return appMinPattern.test(fileName);
});
if (appMinified.length != 1) {
throw new Error('There should be exactly one app-min file');
}
return gulp.src('Views/Home/Index.cshtml')
.pipe(replace(/app-min-[a-z0-9]+\.js/, appMinified[0]))
.pipe(gulp.dest('Views/Home'));
});

gulp.task('clean', () => gulp.src(['wwwroot/js/*.js', 'wwwroot/lib/*.js'], { read: false })
.pipe(clean()));

gulp.task('default', gulp.series(['clean', 'build-css-cerulean', 'build-css-space-lab', 'compress-lib', 'compress-app', 'copy-html', 'copy-templates', 'cache-bust-lib', 'cache-bust-lib-min', 'cache-bust-app', 'cache-bust-app-min']));
1 change: 1 addition & 0 deletions Mundialito/node_modules/.bin/rimraf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a62ade5

Please sign in to comment.